Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Hotkey python


from pynput import keyboard
  
cmb = [{keyboard.Key.shift, keyboard.Key(char='a')},{keyboard.Key.shift, keyboard.Key(char='A')}]
  
current = set()
  
def execute():
  print("Detected hotkey")
  
def on_press(key):
  if any([key in z for z in cmb]):
    current.add(key)
    if any(all(k in current for k in z) for z in cmb):
      execute()
  
def on_release(key):
  if any([key in z for z in cmb]):
    current.remove(key)
  
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
  listener.join()
Comment

how to make a hotkey in python

from pynput import keyboard

# The key combination to check
COMBINATIONS = [
    {keyboard.Key.shift, keyboard.KeyCode(char='a')},
    {keyboard.Key.shift, keyboard.KeyCode(char='A')}
]

# The currently active modifiers
current = set()

def execute():
    print ("Do Something")

def on_press(key):
    if any([key in COMBO for COMBO in COMBINATIONS]):
        current.add(key)
        if any(all(k in current for k in COMBO) for COMBO in COMBINATIONS):
            execute()

def on_release(key):
    if any([key in COMBO for COMBO in COMBINATIONS]):
        current.remove(key)

with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
    listener.join()
Comment

PREVIOUS NEXT
Code Example
Python :: how to make a radio in python 
Python :: how to click on button using python 
Python :: find a file in python 
Python :: extract month as integer python 
Python :: convert list into integer python 
Python :: set python 3 as default ubuntu 
Python :: python append element to array 
Python :: how to make rich presence discord,py 
Python :: how to show line chart in seaborn lib 
Python :: python extract value from a list of dictionaries 
Python :: update print python 
Python :: unlimited keyword arguments python 
Python :: column.replace 
Python :: all files in directory python 
Python :: append method linked list python 
Python :: flask send client to another web page 
Python :: wikipedia python 
Python :: shutil move overwrite 
Python :: Python loop to run for certain amount of seconds 
Python :: im save to a bytes io python 
Python :: enumerate python 
Python :: python get path of current file 
Python :: replace number with string python 
Python :: how to sort dictionary in python by lambda 
Python :: find how many of each columns value pd 
Python :: read csv without header pandas 
Python :: pandas iloc select certain columns 
Python :: python print combinations of string 
Python :: how to write a file in python 
Python :: how to restart program in python 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =