question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

on_press and on_release not executing if one is placed after another

See original GitHub issue

Hi, I’m using on_press and on_release to store any currently pressed keys. Unfortunately, if on_press is placed before on_release, on_release is not being executed. If I switch places of on_press with on_release, then on_press is not being executed. Because of it, I’m using hook as a workaround, in which I’m checking event_type and calling proper function.

pressed_keys = []

def add_key(key):
    pressed_keys.append(key)
    return

def remove_key(key):
    pressed_keys.remove(key)
    return

keyboard.on_press(add_key)
keyboard.on_release(remove_key)    #This is not being executed

Also I have one question: Is there a simpler way of checking in on_press_key if other keys are also currently pressed? modifiers is always empty.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pflatencommented, Apr 5, 2018

Hello,

I was trying to do the same exact thing with on_press and on_release. It looks like the bug was introduced in a recent update (pip version 0.13.1). I downgraded to version 0.11.0 and that got rid of the bug.

To install version 0.11.0 I used the command: pip install keyboard==0.11.0

Hope this helps!

0reactions
rayanfer32commented, Aug 16, 2021
        keyboard.on_release(trigger_event,suppress=False) 

        PASTE_WORD = "@@pst"
        keyboard.add_word_listener(PASTE_WORD, word_paste ,timeout=1)

        LOGIN_WORD = "@@cit"
        keyboard.add_word_listener(LOGIN_WORD, word_login ,timeout=1)

        LOGINPASS_WORD = "@@citp"
        keyboard.add_word_listener(LOGINPASS_WORD, word_loginpass ,timeout=1)

word_listener not getting activated if keyboard.on_release is uncommented System: Windows 8.1

Fixed it by placing the on_release() after all the word_listener()

Read more comments on GitHub >

github_iconTop Results From Across the Web

onPress/onRelease in Android - Stack Overflow
try this: someView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent arg1) { if (arg1.
Read more >
OnRelease not working - Tasharen Entertainment
I have an OnPress function in the same script and it is working just fine. ... Does it not trigger when a held...
Read more >
Handle Press And Release Events in SwiftUI - SerialCoder.dev
Learn how to detect and handle press and release events in SwiftUI, and how to create a custom modifier to simplify that task....
Read more >
MouseArea QML Type | Qt Quick 6.4.1
When set to false, the mouse area becomes transparent to mouse events. The pressed read-only property indicates whether or not the user is...
Read more >
Scripting API: UI.Button.onClick - Unity - Manual
A Button can have multiple listeners. As an example, in the script example below, btn3 can have TaskOnClick added as a second listener...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found