#๐Ÿ”’ keyboard module help

12 messages ยท Page 1 of 1 (latest)

dense lava
#

Hi guys
Someone can help me pls.
I try to use the keyboard module in my program, but if i lock the windows with the win+l, after the bind is not working anymore i try to bind again with a button but didn't work,
This is the command
keyboard.add_hotkey('ctrl+t', command)

high lanternBOT
#

@dense lava

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.

golden wharf
#

can you provide the code

dense lava
#

keyboard.add_hotkey('ctrl+t', self.command)

#

def on_key_event(self,event):
if event.event_type == keyboard.KEY_DOWN:
if event.name == 't' and keyboard.is_pressed('ctrl'):
self.ctrl_t_vissza_test()
return False

keyboard.hook(self.on_key_event)

I try with this solution
With this code working fine,
But this code run every time when i press any buttons ๐Ÿ™

jovial grove
#

!code

high lanternBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

golden wharf
#

What code do you have for self.ctrl_t_vissza_test()

#

Is your concern that the bind won't work after you're on the lock screen view or that it doesn't work after unlocking the screen?

#

Sometimes hooks won't reinitialize properly after locking, you could try this pattern instead if your concern is that things fail after unlocking your session

import keyboard

def ctrl_t_vissza_test():
    pass

def on_key_event(event):
    if event.event_type != 'down':
        return
    if event.name == 't' and keyboard.is_pressed('ctrl'):
        ctrl_t_vissza_test()

keyboard.hook(on_key_event)
keyboard.wait()
high lanternBOT
#
Python help channel closed for inactivity

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.