Like the title says I would like to generate a sequence of keyboard presses from a input.
I have managed to do so and when I open notepad it shows that it works but once i switch to the game it stops working.
The reason from what I have been able to find is that I need to generate hardware level output in some way.
I am very new to python and the fact that I managed to make a code that works and is relatively compact is still amazing to me
This is the code I’ve produced so far
from pynput.keyboard import Key, Controller
import time
keyboard = Controller()
str = input("Paste: ")
new_str = str.replace("↑", "w").replace("←", "a").replace("↓", "s").replace("→", "d")
sleep(5)
for char in new_str:
keyboard.press(char)
keyboard.release(char)
time.sleep(0.5)
What my code does thus far is change arrows pasted from a sequence (EXAMPLE = ↑ ↑ ← ↓ →) into WASD movement (W W A S D as per the example) and turn them into keyboard presses.
Is it possible trough Pynput to change these outputs to hardware level or maybe some other thing I need to import?
And if it isn’t too much trouble please explain in detail what it does or how I can improve my code (as I said I’m very new to coding so I don’t understand the big technical words)
I tried to use Pynput to paste a sequence of arrows and turn them into W A S D movement for a game.
I was expecting to paste the sequence and have it work in game but it only works on Notepad not in the game itself.
According to my research I need to generate hardware level output but I cannot find a easy to understand guide online.
Unity169 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.