r/pythonhelp • • Jun 07 '23

Holding a key down like on a real keyboard

Hello, I'm very new to coding and I want to make my program hold down a key like a person would on a keyboard.

I'm currently using pynput like

   keyboard.press(button)   time.sleep(random.uniform(3, 5))   keyboard.release(button)

But it doesn't hold the key down. It's just one key press. And if I simulate it by using a loop, it still behave different then holding a key on a real keyboard.

Because holding a key on a real keyboard outputs one letter, then a small delay and then it starts printing the letters fast.

Anyone knows the soluion?

3 Upvotes

3 comments sorted by

1

u/RoyoDeBoyo Dec 26 '24

did you find a solution to this problem. I want to do exactly the same thing and can't find anything anywhere lol

1

u/Original_GumPum Dec 26 '24

I couldn't find a solution.
In my case i ended up using key presses with random delays as long as i hold down a button.

0

u/[deleted] Jun 07 '23

[deleted]

1

u/Original_GumPum Jun 23 '23

Thanks for your help!

I'm not understanding what you mean with
def simulate_key_holding(key, hold_time): delay_between_presses = 0.1

where it's getting called from, or am I blind?