-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to detect key being held down instead of a press? #36
Comments
The operating system, or input handling system, will generally only
generate events upon press and release.
You will probably have to decide on a reasonable time out, schedule a timer
with your task and cancel it if the key is released.
On 4 Jul 2017 15:12, "Miail" <notifications@github.com> wrote:
I am currently working on implementing a feature which "does something
while a key is being held down".. As I understand pynput, it seems
impossible to implement such feature? or am i missing something?
This implementation:
from pynput import keyboard
def on_press(key):
if key == keyboard.Key.cmd_l:
try:
print('- Started recording -'.format(key))
except IOError:
print "Error"
else:
print('incorrect character {0}, press cmd_l'.format(key))
def on_release(key):
print('{0} released'.format(key))
if key == keyboard.Key.cmd_l:
print('{0} stop'.format(key))
keyboard.Listener.stop
return False
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
Only detect one press, also when the key is being held down.. It doesn't
seem to read the stream..
I though maybe the use of a while loop would help, also giving the way the
problem is stated, so i tried this...
from pynput import keyboard
def on_press(key):
while key == keyboard.Key.cmd_l:
try:
print('- Started recording -'.format(key))
except IOError:
print "Error"
else:
print('incorrect character {0}, press cmd_l'.format(key))
def on_release(key):
print('{0} released'.format(key))
if key == keyboard.Key.cmd_l:
print('{0} stop'.format(key))
keyboard.Listener.stop
return False
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
Which resulted in being stuck in a while loop.. and not come outside..
can the library be used like this, can it detect "a key being held down"?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#36>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAjOY1PbB21sRIahSpIERVmZDRjRAcZ6ks5sKjo_gaJpZM4ONVh7>
.
|
Sorry?.. Not sure I understand how the timer should be involved, and how Are thinking of a solution in which |
You could use, for example, I am currently on a flight, so I can't really help you more; as this is out of scope for this library, I'll close this issue. |
I am currently working on implementing a feature which "does something while a key is being held down".. As I understand pynput, it seems impossible to implement such feature? or am i missing something?
This implementation:
Only detect one press, also when the key is being held down.. It doesn't seem to read the stream..
I thought maybe the use of a while loop would help, also giving the way the problem is stated, so i tried this...
Which resulted in being stuck in a while loop.. and not come outside..
can the library be used like this, can it detect "a key being held down"?
The text was updated successfully, but these errors were encountered: