Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

keyboard listener python

from pynput import keyboard

def on_press(key):
    if key == keyboard.Key.esc:
        return False  # stop listener
    try:
        k = key.char  # single-char keys
    except:
        k = key.name  # other keys
    if k in ['1', '2', 'left', 'right']:  # keys of interest
        # self.keys.append(k)  # store it in global-like variable
        print('Key pressed: ' + k)
        return False  # stop listener; remove this if want more keys

listener = keyboard.Listener(on_press=on_press)
listener.start()  # start to listen on a separate thread
listener.join()  # remove if main thread is polling self.keys
Comment

keyboard listener python

from pynput import keyboard

def on_press(key):
    if key == keyboard.Key.esc:
        return False  # stop listener
    try:
        k = key.char  # single-char keys
    except:
        k = key.name  # other keys
    if k in ['1', '2', 'left', 'right']:  # keys of interest
        # self.keys.append(k)  # store it in global-like variable
        print('Key pressed: ' + k)
        return False  # stop listener; remove this if want more keys

listener = keyboard.Listener(on_press=on_press)
listener.start()  # start to listen on a separate thread
listener.join()  # remove if main thread is polling self.keys
Comment

PREVIOUS NEXT
Code Example
Python :: cv2 resize 
Python :: normalise list python 
Python :: opencv flip image 
Python :: how to get the user ip in djagno 
Python :: pandas predict average moving 
Python :: No default language could be detected for django app 
Python :: python sorted descending 
Python :: filter nulla values only pandas 
Python :: pairplot size 
Python :: list map lambda python 
Python :: pandas split dataframe to train and test 
Python :: tkinter window title 
Python :: python generate uid 
Python :: which python mac 
Python :: pip install contractions 
Python :: pandas to_csv delimiter 
Python :: bail bond cowboys 
Python :: Simulate webcam and microphone selenium 
Python :: how to make a multichoice in python 
Python :: check if directory exists python 
Python :: python youtube video downloader 
Python :: how to print numbers from specific number to infinite inpython 
Python :: python volver al principio 
Python :: truncate date to midnight in pandas column 
Python :: write a program to check whether a character is vowel or consonant in python 
Python :: how to sort a dictionary by value in python 
Python :: np array to wav file 
Python :: replace the jinja template value inside the dictionary python 
Python :: How do I start a DataFrame index from 1? 
Python :: YouCompleteMe unavailable: requires Vim compiled with Python (3.6.0+) support. 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =