PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 12, 2022

[FIXED] How bind/map global hotkey when using Python Tkinter?

 September 12, 2022     cross-platform, global-hotkey, python, tkinter     No comments   

Issue

I want to bind/map a global hotkey, which also works when application window is minimized and user not focused on it. I'm looking for a cross-platform way. Can I do this using Tkinter?


Solution

With tkinter, if the window does not have keyboard focus it won't receive the keypress events so you won't be able to do what you want.

However, with pynput you can listen to the keypress events:

from pynput.keyboard import Listener

def on_press(key):
    print("PRESSED", key)


with Listener(on_press=on_press) as listener:
    listener.join()

This should be cross-platform (but with some patform specific limitations).



Answered By - j_4321
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing