OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

how can a certain keypress be ignored while using the python keyboard module?

  • Thread starter Thread starter mattrichardson100
  • Start date Start date
M

mattrichardson100

Guest
I have a simple bit of code that launches random files then uses the keyboard module to do certain things to that file.

eg.

Code:
def my_exit():
    "exits"
def nextfile():
    "does the next thing"
def deletefile():
    "deletes the thing"

keyboard.add_hotkey("n", nextfile)
keyboard.add_hotkey("d", deletefile)
keyboard.add_hotkey("esc", my_exit)

for g in allfiles:
    while True:
        chosen = random.choice(allfiles)
        os.startfile(chosen)
        key = keyboard.read_key()

This works fine if all i do is press one of the hotkeys. But the issue is if i press a different key (eg. page down) to control the file that has opened, it wont react to the hotkeys - it's like the python script has lost it's focus.

This is my first post here and i'm sure it a simple fix for someone who knows what they are doing. Thanks
<p>I have a simple bit of code that launches random files then uses the keyboard module to do certain things to that file.</p>
<p>eg.</p>
<pre><code>def my_exit():
"exits"
def nextfile():
"does the next thing"
def deletefile():
"deletes the thing"

keyboard.add_hotkey("n", nextfile)
keyboard.add_hotkey("d", deletefile)
keyboard.add_hotkey("esc", my_exit)

for g in allfiles:
while True:
chosen = random.choice(allfiles)
os.startfile(chosen)
key = keyboard.read_key()
</code></pre>
<p>This works fine if all i do is press one of the hotkeys. But the issue is if i press a different key (eg. page down) to control the file that has opened, it wont react to the hotkeys - it's like the python script has lost it's focus.</p>
<p>This is my first post here and i'm sure it a simple fix for someone who knows what they are doing. Thanks</p>
 
Top