An IF statement is supposed to choose a direction if a character is uppercase, but it doesn't

111 Views Asked by At

I am currently trying to write a part of a script that will write a message to people on a games server to let them know that I am AFK.

I am using pydirectinput over pyautogui for this instance because pyautogui does not work in-game, and pydirectinput does.

def AFKmessage():
    print("\n> Typing message...\n")
    message = str("From AFK Script: " + str(username) + " is currently AFK. Please do not disturb them. Thank you.")
    mess_place = 0
    for i in range(len(message)):
        newchar = str(message[mess_place])
        checkUP = newchar.isupper()
        if checkUP==True:
            pydirectinput.keyDown("shift")
            pydirectinput.press(newchar)
            pydirectinput.keyUp("shift")
        else:
            pydirectinput.press(newchar)
        mess_place = mess_place + 1

I am yet to implement a way to type special characters here.

Firstly, the script assigns the message to the variable 'message'. 'mess_place' exists as a counter to keep track of where abouts the program has processed in the string. We then see a FOR loop which repeats the cycle for the amount of characters there are in the string. Variable 'username' is assigned earlier on in the script compared to the section shown here. The current character is assigned to 'newchar' and the variable 'checkUP' checks to see if the character is uppercased, which it can do successfully. However, even if 'checkUP' is True, the script won't attempt to capitalise the letter with the 'shift' key, it just misses it out completely, and I don't understand why that is.

Can anyone help me please?

0

There are 0 best solutions below