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.

Can't map some keys

See original GitHub issue

Hi, thanks for this library, I’m trying to make use of it to create a simple custom hotkey “alias”. I’m on a MacBook Air running Linux (Gentoo).

import keyboard
import time

keyboard.clear_all_hotkeys()

keyboard.add_hotkey('win+c', lambda: keyboard.send('ctrl+c'))
keyboard.add_hotkey('win+v', lambda: keyboard.send('ctrl+v'))

keyboard.add_hotkey('win+l', lambda: keyboard.send('ctrl+l'))
keyboard.add_hotkey('win+e', lambda: keyboard.send('ctrl+l'))

while True:
    time.sleep(10)

On the script above, win+l and win+e are calling the same keyboard hotkey but only win+e works. I’m hitting those hotkeys on Chrome browser.

If I change those mappings to a debugger output:

keyboard.add_hotkey('win+c', lambda: print('ctrl+c'))
keyboard.add_hotkey('win+v', lambda: print('ctrl+v'))

keyboard.add_hotkey('win+l', lambda: print('ctrl+l'))
keyboard.add_hotkey('win+e', lambda: print('ctrl+l'))

I do see the output on the console. Do you have any idea what could be cause these events to not be correctly processed by chrome?

P.S.: I don’t think it’s relative to Chrome, as the same hotkeys don’t work on other applications (e.g. termite).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
bopprehcommented, Feb 5, 2017

Hmm, the suppress code is even trickier than the hotkey code, and was introduced by a pull request. I’ll have to take some time to check it, but it may take some days.

And by the way thanks for the bug reports. These are very useful.

1reaction
bopprehcommented, Feb 4, 2017

Your code was not working because of the keyboard.is_pressed(part) part when checking if the hotkey has been completed. When the handler is called, the key has already been registered as released and therefore the check fails.

The fix was indeed tricky, but I implemented on the master branch as a trigger_on_release flag. Please let me know if you find any problems with it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing a Key? How to Remap and Fix Your Keyboard ...
Fix a Missing Key. Do you have a missing or broken key? Just map around it. It might take some adjustment because you'll...
Read more >
Keybinds problem, can't map certain keys : r/TowerofFantasy
Keybinds problem, can't map certain keys. hi, i was wondering if some of you have a similar problem : My weapon skill and...
Read more >
Unable to map some keys on Linux - Answers HQ
Unable to map some keys on Linux ... Mouse/keyboard settings menu ... Open game in Linux under steam, go to in-game settings, try...
Read more >
Not able to map keys to Ctrl+Left or Ctrl+Right with ...
I'm wondering if it's some lingering settings on PowerToys, or did a recent Windows update blotch PowerToys' Keyboard Manager? My key mapping:
Read more >
How to map a controller to keyboard keys on Windows 10
Map controller to keyboard. While most modern PC games have controller support, some of them offer better gameplay if you use a keyboard....
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