0

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?

Jeremy
  • 661
  • 7
  • 19
  • 1
    what happens if you utter `pydirectinput.press("A")` instead of `pydirectinput.press("a")` - what is the shift pressing all about? did you research those functions you are using? – Patrick Artner Apr 23 '22 at 23:06
  • 2
    why all the usages of the str() function? why iterage the string by index instead by letter? `for letter in message: ... so something with letter`. Why press letter by letter and not simply post the whole string at once? – Patrick Artner Apr 23 '22 at 23:12
  • 1
    why have all the examples for this pydirectinput `sleep()s` int the key press code ynd yours has not? – Patrick Artner Apr 23 '22 at 23:13
  • Possibly related to this [issue](https://github.com/learncodebygaming/pydirectinput/issues/7). You may want to open an issue on the github repo if you can reproduce this minimally, ie. if you are unable to type a single capitalized character in a text editor with a script that does only that. As it stands there are too many variables to tell exactly why this isn't working as it could be due to the library, your code, or the specific application you're attempting to use this with – Jeremy Apr 23 '22 at 23:34

0 Answers0