#๐Ÿ”’ pynput.keyboard.Listener

20 messages ยท Page 1 of 1 (latest)

viscid echo
#

im making a program that includes some commands, lets say rm the goal was to be able to run the rm~ without pressing enter, waiting for some time is importance since while wafting we show all the possible commands with that name, lets say rmq that does something

my first idea was to have a global timer, and it will basically wait for a duration and when the delay is enough it will run what ever is in the buffer, now the on_click handler will reset the timer to 0 but im worrying about race conditions

nimble pikeBOT
#

@viscid echo

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

near moth
# viscid echo im making a program that includes some commands, lets say rm the goal was to be ...

you can have a variable to store time.time() after every keystroke and some loop you can again call time.time() and calculate the difference between those two which will give you the total time elapsed from the last keystroke to the current time in seconds.

And you don't need to worry about race conditions as long as you can guarentee there's only one process doing write operation on that variable

#

if there are multiple processes that are doing write operations then you'll have to use some synchronization tools

viscid echo
#

also the thread was not defined by me, it was created by the pynput.Keyboard

near moth
viscid echo
#

!doc pynput.keyboard.Listener

nimble pikeBOT
#

class pynput.keyboard.Listener(on_press=None, on_release=None, suppress=False, **kwargs)```
A listener for keyboard events.

Instances of this class can be used as context managers. This is equivalent to the following code...
near moth
viscid echo
#

what alternative you use??

#

keyboard??? meh it sucks

#

same on pyautogui

near moth
#

haven't really done anything too related to keyboard so can't recommend any. I've only used the keyboard library a couple of times for some basic things

viscid echo
#

oh

#

anyways thanks ill close this now

#

!close

nimble pikeBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.