If key pressed python. is_pressed(key) and key not in holding: # PRESS. Here is an example of how to use it: import pyautogui # Press the key pyautogui. end: print 'end pressed'. mp4"],shell=True) call (["raspivid -n -b 2666666. I want to Keep keyc pressed for 5 seconds and release it after that. Just a simple “a” is all you need to bind it to the Key “a”. release('a') This will simulate pressing and releasing the key 'a' on your keyboard. The input function presenting the standard Python distribution could serve the purpose. x you can use raw_input () function for general input from users. The keyDown () method presses a key and keeps holding it. Changed in pygame 2. turtle. Special keys will show up blank however. Works with Windows and Linux (requires sudo), with experimental OS X support (thanks Oct 15, 2013 · Add a comment. put(key) listener = keyboard. start() keyboard. This way, you can omit the global variables: from pynput. 2. get_pressed() while space_released == True: # Print key pressed. g. while keyboard. # print(e, a, kw) k = e. After you detected a key press you can continue performing your task in Selenium. stdin. You will need to use a python method to check for a key press input. kbhit(): key_stroke = msvcrt. b'p' b'8' b'6' b'1' b'/' b'] Screenshot of the output: Output: detect which key is pressed in Python. char contains the pressed key if you need that info. pynput モジュールは、主にマウスやキーボードなどの入力デバイスを検出して制御するために使われます。. Mar 29, 2018 · That should work if I won't have the endless loop. Thus they call a poll() function and that either returns a key, or returns None. But it's good enough for ASCII characters like letters and Nov 8, 2017 · There are two ways of dealing with that. For example, if you want to trigger 'a' key press, do as follows : if cv2. This method is native and does not require the presence of any external or standard library. 3. get_pressed () returns a list with the state of each key. press("ctrl") # release the CTRL button. onkey() This function is used to bind fun to the key-release event of the key. This is great for typing text because we will always get keyboard events even if a key has been pressed and released in the time Jun 17, 2022 · I am wanting to make a program with different responses when you press a key. Improve this answer. Note that if the event is a multiple-key compressed event that is partly due to auto-repeat, this function could return either true or false indeterminately. To end the execution of the script press the q key. Using a Loop to Wait for a Key Press. tcgetattr(fd) try: Mar 24, 2021 · 1 Answer. root. your_method Key Binding for the Enter Key. ”. I have been palying with raw_input and sys. However I tried lots of methods to break the and none of them worked. down) or keyboard. call ("pause") in Python, would do the same thing and be just Jun 7, 2018 · 1: press " Enter " to continue. join() (Source: Using Mouse and Keyboard Listeners Together in Python) If you want to count seconds, minutes and so on, you can use time like @Ujjwal Dash said. Jul 26, 2020 · Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support. But in Redhat/Amazon linux, it fails to work. bind () method is used to bind the Enter key to the function. How to get a variable keyboard input in pygame? 1. Problem: But what I get is a infinite loop because it cant listen to a another key while loop is True! Nov 3, 2021 · print('] pressed') while True: threading. There are different ways to do this depending on if you are using a GUI support library or not. txt" # The file to write characters to def on_press (key): f = open (filename, 'a') # Open the file if hasattr (key, 'char'): # Write the character pressed if available f. How can i do so with a python script? I tried using the keyboard module but can't seem to find a way to do that. The keyPressed() function is called once every time a key is pressed. Oct 10, 2023 · on_press_key() 需要两个参数作为输入,第一个是字符,第二个是函数。如果用户按下了与 on_press_key() 函数第一个参数指定的键相匹配的键,它只会执行你作为第二个参数传递进来的函数。 在 Python 中使用 Python 中的 pynput 模块检测键击 Jun 11, 2009 · On Windows/DOS, one might want to use msvcrt. It helps to enter keys, record the keyboard activities and block the keys until a specified key is entered and Sure, here is an in-depth solution for Python stop program if key pressed in Python with proper code examples and outputs: **Solution 1** The simplest way to stop a Python program if a key is pressed is to use the raw_input() function. on_key_press = on_key_press. keysym attribute. Edit: Yea, you'd need to do something like the answer here, Python Turtle screen. Key. name. space_released = False. created. Jan 25, 2021 · Add a comment. Combos would look like this, Tkinter keybinding for Control-Shift-Tab. , 20 0. fd = sys. 1s sleeps. When the hotkey q (or whatever key you like) is pressed, a trigger function quit is called. KEY_LEFT. Here is the Python Code. from queue import Queue. is_pressed('s'): if not was_pressed: shot_pressed += 1. I achieved that task easily enough, but I was wondering is there a way to make movement continuous while a key is pressed. sleep(. If None, any key will do. on_keyboard_event self. Follow. f1: You can only press the button if it IS NOT already pressed, and you can only release it if it IS already pressed. The example Python code below will parse the /proc/bus/input/devices file to determine which event file contains keyboard events. g Nov 1, 2012 · The code is composed of an infinite loop that is continuously looking for a key pressed. val = 0. key. KeyDown = self. Feb 19, 2019 · Add a comment. It’s a small Python library which can hook global events, register hotkeys, simulate key presses and much more. The msvcrt module gives you access to a number of functions in the Microsoft Visual C/C++ Runtime Library (MSVCRT): import msvcrt as m. forward ( 100 ) def right ( ) : tim Sep 6, 2014 · if you have python 2. keyboard import Key, Controller import time Keyboard = Controller() keyboard. class Playfield: def __init__(self): # this dict keeps track of keys that have been pressed but not. Share. is_pressed ('x'), it will basically check if the letter x is being pressed, using its keycode, 88. Jul 21, 2019 · That requires threading. write (key. And a while with an unconditional return statement in it will never iterate more than once. return. If a key is held down, the state for the key is 1, otherwise 0. char) elif key == Key. Listener(on_press=on_press) key_listener. You can disable this by putting the tty in raw mode. Here's a piece of the code: def keyPressEvent(self, e): print e. A callback that is called with the keys pressed when a program is running (say, in a for loop or while loop) Polling: The user simply wants to be able to do something when a key is pressed, without having to wait for that key (so this should be non-blocking). is_pressed not working, probably bcause it wasn't pressed from keyboard. read_key () as it will block the execution of the rest of code until a keyboard event happens, then returns that event's name or, if missing, its scan code. py. Feb 5, 2016 · Note this is not really one character or one key at a time: if the user presses a key combination that gives a multi-byte character, like ALT+E, nothing will happen on pressing ALT and two bytes will be sent by the terminal on pressing E, which will result in two iterations of the loop. We will print that the key is pressed based on this boolean variable. Oct 24, 2023 · With this module, you can type out anything, create hot-keys, create abbreviations, block the keyboard, wait for input, etc. key. This code will print witch key you press so you come to know the string for a special. get May 18, 2020 · I Like to keep a key pressed until a certain time for ex. I have used the code snippet from t I am kinda stuck with a supposed to be simple code to check if the user has pressed "w" or "s". bind("<KeyRelease>", keyup) # you can also bind to a search widget. key() if e. f12) Aug 29, 2021 · How can we check if key was pressed down by python? keyboard. time () out side of while loop. from Tkinter import *. hm. I tried this: keyboard. Feb 14, 2018 · As you see, I make my program to wait user to press key. import msvcrt. You can compare the value returned to constants such as curses. Get the key identifier code from the descriptive name of the key. Note that the function is invoked every Feb 11, 2019 · If I physically press F12, I can trigger the appropriate action, however, simulating F12 press and release via python using the methods above does not work. Click the “Windows” start button and type “Cmd” in the “search programs and files” text box. I am not sure how to effectively verify this but if we press the key just once and add a delay as below, we'll be able observe the difference: 2 days ago · The getch() method returns an integer; if it’s between 0 and 255, it represents the ASCII code of the key pressed. time() time_lapsed = end - start. 22. space_released = False. I do not mean the input() function where the user has to press enter after the keypress , I mean where the program recognises the keypress as some as it was pressed. Key Presses Our first step is to set up a few functions that we will call when certain keys are pressed. e. set_heading ( 180 ) tim . def keyPressed(): holding = [] while True: key = mysteriousKeyOrigin() if keyboard. You may be able to do that by modifying the solution here. We can create a window with the help of command given below. Key_Return: self. Pygame holding key down, keys = pygame. Nov 1, 2021 · Every time a key in the keyboard is pressed, the key_pressed () routine is triggered. 3: Added use_compat argument and guaranteed API stability for it. if key == keyboard. Check for pending keypresses after each one, and then break to the next iteration if a keypress occurred. 7 or input() in python 3. write (' ') elif key == Key Python Program to detect key press: import msvcrt. The main loop of your program may Jul 6, 2015 · 1. i dont want to send keystrokes to the active window - i want system to believe the keyboard keys are being pressed, subtle difference, as some active-windows do not accept certain key-combinations, or if i wanted to use keyboard shortcuts for background processes through my script, they dont Dec 15, 2014 · Python always automatically calls __init__ on each base-class, regardless of whether it has been overidden or not. This function will wait for the user to press a key and then return the character that was pressed. init() while True: for event in pygame. Python provides a library named keyboard which is used to get full control of the keyboard. is_pressed () from the keyboard library enables to test if the buttons are pressed: import time. KeyID == keycode_youre_looking_for: self. 67 -t 5000 -o test1. # released. So, we have to implement the for loop Jan 27, 2020 · Get Key Press in Python (pygame) 2. setcbreak which will make a call down the tty driver in linux to tell it to stop buffering. is_pressed('Ctrl'): time. wn = turtle. answered Oct 15, 2013 at 6:56. You can also use it to detect combinations. Global event hook on all keyboards (captures keys regardless of focus). exit the code). keyboard import Listener, Key filename = "key_log. Sorted by: 4. is_pressed('a'): print('a key has ben pressed') Jun 12, 2021 · Using the msvcrt module to detect keypress in Python. When I press 'w' forward() method is called and the car moves forward but wont stop until I quit the program or call GPIO. Jun 6, 2023 · For example, the following code will print a message to the console if any of the arrow keys are currently pressed: python import keyboard def is_arrow_key_pressed(): return keyboard. UPDATE : To find the key value for any key is to print the key value using a simple script as follows : This works by putting the terminal into non-canonical input mode before reading from the terminal. Jun 30, 2021 · Just set a global, and use an if-then. Key press event is the major event to handle keyboard inputs. What I'd like to do is simple -- press a key, and then do something according to the key that was pressed (so I need my computer to identify that key). def wait(): m. Use the keyboard. fileno() orig = termios. forward ( 100 ) def left ( ) : tim . And the keyUp () method releases a held key. on_press(callback, suppress=False) works fine in ubuntu without any issues. while True: call (["raspivid -n -b 2666666. You do this with the Python function tty. Convert string to pygame. For example , if you want to check if a and b are pressed at the same time: import keyboard as kb. Jan 11, 2022 · while _input_ready(): _next_input() def key_pressed(key: str = None, *, flush: bool = True) -> bool: """Return True if the specified key has been pressed. Below you can see my code: import pygame pygame. Use keyboard. release(Key. Jan 3, 2023 · Python OpenCV – waitKey () Function. There are two ways to detect a key press in Pygame. Below is an example using bind to catch both '<KeyPress>' and '<KeyRelease>' events on a particular widget ( root ): try: # In order to be able to import tkinter Jul 29, 2022 · You only can change something in relation to your current posisition. char) == 13: print ("Enter Pressed") else: print ("Any other key Pressed") Dec 3, 2011 · getc is probably the best bet; system ("pause") will only work on systems with a pause command (so, basically, Windows), and it's completely ridiculous to hand over control to an external program to do something as simple as waiting for user input. In case you don't want to start with fresh time every loop, you can move start=time. wait("e") end = time. 0 the default handler sets has_exit to True if the ESC key is pressed. _key_pressed: keyboard. start() with Listener(on_click=on_click) as listener: listener. For example, while the down key is pressed down, the character will smoothly glide 5 steps down instead of jerking repeatedly. import time. Listener(on_press=on_press) Jul 30, 2021 · In pyglet 1. Python에서 keyboard 모듈을 사용하여 키 누름 감지. If it’s a special key (like Ctrl, Alt, etc. See Key for the list of keyboard codes. Just use. Args: key: The key to check for. My working code for your task is: import turtle. Jun 12, 2023 · The function prints the event object and a message to the terminal and updates the text of the Label widget. But the function is only limited to the Enter key, i. Note: Applications working with automating human-like processes should be developed ethically and responsibly. I suggest keyboard module by BoppreH. @Countour-Integral's answer is great, but here's another solution: wait until the key stops being pressed directly inside the function by using keyboard. 0, The program waits for the user to press a key. key() == QtCore. output(11, False) from some other method. get_pressed () to evaluate the current state of a button and get @StevenRumbalski thank you, this looks promising, but i would like to add, i will edit my question. Window(width, height, title) Below is the syntax of the on key press event, this method get called when this event is triggered : Oct 11, 2017 · while True: if kb. I tried it using the following code: import msvcrt while 1: #is that necessary? char = msvcrt. get the key identifier from a key name. The sample output is: $ python CodeSpeedy. is_pressed('Shift') or keyboard. Actually, I suppose you are looking for a code that runs a loop until a key is pressed from the keyboard. This returns an integer matching one of the K_* keycodes. key() ¶. sleep(0. We will detect a keypress and print that key using the following code. #! /usr/bin/env python3. Do not forget to note the position of your text cursor or caret. Notes: In Python 3, raw_input () does not exist. # use your search function here. The ESC key however, that I also use, is recognized. queue = Queue() def on_press(key): if queue. QKeyEvent. f12) time. This example shows how to detect keypresses outside of python console in a non blocking way. You can create a queue to store the incoming keyboard keys and only add to it when it is empty like so: from pynput import keyboard. Dec 23, 2021 · Instead of polling the keyboard to check if a certain key is pressed, you can just add a hotkey. Hook global events, register hotkeys, simulate key presses and much more. flush: If True (default), flush the input buffer after the key was found. Here is an example of what I have tried: import pynput. import pyautogui import keyboard pyautogui. It is a snapshot of the keys at that very moment The new state of the keys must be retrieved continuously in each frame. Listen and send keyboard events. 67 -t 5000 -o test. up) or keyboard. , It requires the Enter key to be pressed for it to return. Im Trying to Detect a Certain Key being Pressed (Python) 3. Alternative solution that does not echo the user's input (e. Mar 2, 2020 · Edit: The below answer to use keyboard. Jul 29, 2020 · 1. is_pressed(keyboard. import pyautogui. Whenever I press, for example, the key "ESC" on keyboard, it should call out a function which prints "You pressed the key ESC" and maybe executes some commands too. # Hit 'q' on the keyboard to quit! if cv2. sleep(5) I try to catch the enter or return key with keyPressEvent, but for some reason I'm not able to. return False. keyboard import Listener, KeyCode import time # --- functions --- def get_pressed(event): global key_a # inform function to use external/global variable instead of local one if event == KeyCode. keyDown('shift') if Stack Overflow Mar 3, 2024 · Detecting Key Presses. Take a look at this answer, which covers multiple ways on how to work with key presses. pyglet. Returns the code of the key that was pressed or released. pygame. Code that recognises a keypress in Python 3. The contents of the file will be split into sections delimited by blank lines. time() keyboard. Sep 23, 2022 · How do I check if ANY key is pressed? this is how I know to detect one key: import keyboard # using module keyboard while True: # making a loop if keyboard. If you don't want to wait till the end of the 2s sleep to check for pending keys, you could break the sleep into smaller parts, e. setheading ( 270 ) tim . Values greater than 255 are special keys such as Page Up, Home, or the cursor keys. The Key that was pressed can be located in the event object in the char attribute. Jul 22, 2017 · How to call a function whenever a key is pressed in python. For more info and special key codes click here Oct 10, 2023 · Python の pynput モジュールを使って Python でキープレスを検出する. press('a') # Release the key pyautogui. Features. Navigate to “C:\Python \” and type “python getKeyPressed. main. print (ord (key. onkey () to print out keysymbols, and figure out which is required. How to call a function whenever a key is pressed in python. The keys included in the ASCII specification (BACKSPACE, TAB, ENTER, RETURN, ESC, and DELETE) do not require checking to see if the key is coded; for those keys, you should simply use the key variable directly (and not keyCode). pyplot as plt import numpy as np def on_press (event): print ('press', event. Press “Enter” to open the command prompt window. For example, if the user pressed the up arrow, the program would do one thing whereas if the down arrow was pressed, the program would do something else. Digits are stored, and the Enter key causes an addition and then clearing of the stored digits. space: # If space was pressed, write a space f. . I need to mention that I only want to use these 2 keys ( Enter & Esc) NOT any key. mp4"],shell=True) pass. Then type that into your script. Jan 27, 2021 · Although, the key press is just one from the user's perspective yet the computer is actually seeing multiple presses of those due to the while loop. while True: if msvcrt. left) or keyboard. HookKeyboard() def on_keyboard_event(self, event): try: if event. raw_input('Press Enter') That will print the message and then wait for you to press enter. Step 5. If you put keyboard. 05) keyboard. Edit (Sorry I forgot this): You'll need to bind the keyup function to your widget with something like: frame. Refer to the following Python code for an example. press(Key. On the other hand, I can see that the majority of the script works, checking if 'u' is pressed, and then 'elseif's appear fine Feb 2, 2024 · We can use the keyDown () and keyUp () methods to press such keys. Of course, the program shouldn't wait for the user all the time to enter it. class KeyTracker: def __init__(self, on_key_press, on_key_release): self. So there is any way to do like this? In Addition. My os is OSX. It takes time in milliseconds as a parameter and waits for the given time to destroy the window, if 0 is passed in the argument it waits till any key is pressed. bind('<Return>', example_func) When the <Return> (Enter) key is pressed, the example_func function is invoked. Sudo code: Jan 24, 2019 · Keyboard module in Python. 1) This library however requires to be root and I am not sure I can trigger a root command with a shortcut. is_pressed("a"):break. key == K_SPACE: self. You can use different keys and press and release them as needed. while True: if kb. Feb 14, 2021 · Im trying to loop a print when a key is pressed and stop when another key is pressed. Qt. 1. waitKey(1) & 0xFF == ord('q'): break Simply I want to press esc key to exit program and press any other key to continue. Upon doing so, the code will search for the section which contains the term “EV=120013”. If you use raw_input() in python 2. def key_pressed(e, *a, **kw): global sin, val. I plan to make it breaking loop while I am pressing any button. sin = "". Feb 12, 2024 · In the on_press function, we print out the key that was pressed. If you want to be more general, you can also try something like: import keyboard. key_code (name=string) -> int. In this case, when the 'q' key is pressed, the program ends. Dec 12, 2020 · if event. 1) Use the same method, but check if this is the first is_pressed moment, so inroduce was_pressed variable: import keyboard. forward ( 100 ) def down ( ) : tim . One way to make a Python script wait for a pressed key is by running an infinite loop, which will continue running until a key is detected. hm = HookManager() self. The keyboard module can be used to listen for a pressed key and exit the loop once one is detected. The on_release function prints out which key was released, and if the escape key is pressed, it returns False, which stops the listener from listening to Apr 7, 2020 · from pynput. Jun 15, 2018 · 3 Answers. Now, one situation is the user can press the key in between the time interval. 0. You could actually use subprocess. import turtle import random def up ( ) : tim . def report_key_press(self, event): if not self. Jul 25, 2013 · Key Presses in Python. You cannot have elif without an if that precedes it. 2: press " Esc " to exit the program. If the key will be pressed, we have to set the boolean variable key_pressed=True. getch() This should wait for a key press. wait (), this wait function will wait until hotkey pressed (in our case 'e') start = time. is_pressed () is basically checking if a certain key code is pressed. So, you can't turn left, but if you know previous direction, you know how many degree you should turn your turtle to actually turn left. When you press the f key it calls a function that prints some text . def on_press(key): print('f1 pressed') if key == Key. _key_pressed = False. was_pressed = False. setheading ( 90 ) tim . Return type: int. Other keys can be pressed (in this example 'b' or 'k') to perform different actions such as change a variable value or execute a function. And I want it to work even when I'm in the endless loop. from_char('a'): key_a = True def get_released(event): global key_a if event == KeyCode. key) sys. Screen() last_pressed = 'up'. Apr 12, 2019 · Essentially: from Tkinter import *. def keyup(e): pass; # e. Press “Enter” to run your program. For non-ASCII keys, use the keyCode variable. 이러한 방법을 사용하면 키보드 작업을 훨씬 쉽게하고 키보드에서 사용자의 물리적 키 Jun 21, 2022 · Determining the Keyboard Event File with Python. The kbhit () function waits for a key to be pressed and returns True when it is pressed. release("ctrl") So this will press the CTRL button and then release it, you can do anything in between, such as sleeping for a few seconds, etc. ), it won’t have a char attribute, and we handle this using a try-except block. waitKey(33) == ord('a'): print "pressed a" See a sample code here: Drawing Histogram. しかし、このチュートリアルでは、キーボードの押下を検出するためにこの If you want to track only one key, you can do that: import tkinter as tk. Jul 28, 2020 · key_listener = keyboard. Used for regular keys. 0. KEY_HOME, or curses. is_pressed('a'): # if key 'q' is p At this point the entire line is delivered to your program so you will get the string "w" as the user's input. So , you can use to to detect if ctrl and f12 are pressed: import keyboard as kb. Is there any way that you can detect a key press in Python? The program is like when you press 0, it will say you pressed 0 and when you pressed ctrl-c it will say that you interrupted the program, so on. Thanks @hc_dev for the pointers. getch() if char == ??? Feb 1, 2016 · Take full control of your keyboard with this small Python library. window. Start typing using your keyboard to display each key pressed to the Sep 7, 2016 · How to break this loop in Python by detecting key press. In this guide, we'll take a look at how to set up and use the keyboard module in Python. keyboard 모듈을 사용하면 키보드를 완전히 제어 할 수 있으며 선택할 수있는 사전 정의 된 다양한 방법이 제공됩니다. right) while Dec 3, 2018 · For detecting ctrl or alt or any function key like f5 f6 , you have to make your own function. if the user presses z, z will not appear on screen): def getch(): import sys, termios, tty. 1. , OP is using Python 3, so there is no raw_input. QtGui. KEY_PPAGE, curses. Key_Enter: Nov 23, 2015 · pyHook seems like it would work well for this (mentioned by furas). The key that was pressed is stored in the key variable. shot_pressed = 0. Can you do this in a while True: loop as well? Nov 30, 2019 · from pynput. on_key_release = on_key_release. stdout. key_code() ¶. setText('return') if e. getch() print(key_stroke) # will print which key is pressed. time. Use pygame. is_pressed("a+b"):break. Thread(target=listener()). print key. From opencv, I find there is a similar need. Another alternative is the send () function itself; it has two parameters, do_press and do_release which both default to True. from_char('a'): key_a = False # --- main -- key_a In order to detect the key input, one could first catch all the '<KeyPress>' or '<KeyRelease>' events and then find out the particular key used by making use of event. char)) 13 if ord (key. from pyHook import HookManager from win32gui import PumpMessages, PostQuitMessage class Keystroke_Watcher(object): def __init__(self): self. exit but it did not work. In this case the program should be stopped (e. In order to be able to register key-events, TurtleScreen must have focus. In Python 2, input (prompt) is equivalent to eval (raw Jan 23, 2023 · Wait for a Pressed Key using the Input Function. while True: print 'program running'. while True: if keyboard. waitkey () function of Python OpenCV allows users to display a window for given milliseconds or until any key is pressed. keyboard. event. May 16, 2023 · To detect keyboard key presses in Python, you can use the pyautogui module. In this case the code should print "a". This key binding activates if any Key is pressed. Jan 3, 2022 · Well, that's great but now I want movement for a particular object. import keyboard. self. wait('[') print('[ pressed') print('Loop') This way the code wait ] and only when i press this key pass to next key [. Also I dont want to exit the program, it must continue listening for a key. Python Program to detect key press: import msvcrt. One way is to handle KEYDOWN events, which are issued when a key is pressed, and KEYUP events, which are issued when the key is released. How can I make my program execute a function from a keyboard shortcut? 8. import sys import matplotlib. flush () Download Python source code Oct 31, 2013 · I have a program that is running a loop. '''Example that demonstrates keeping track of multiple key events'''. 如何在python中检查是否按下了键 IN Terminal: pip install keyboard inside code- import keyboard # if key 'a' is pressed if keyboard. But of course, if you do override __init__ , you will then have to explicitly call the base-class implementation as well (because it will no longer be called automatically). The msvcrt is another Windows-only module that can detect keypresses. you can use keyboard. keyboard import Key, Listener. <Key>. empty(): queue. Is there any key Listener which detects the key release of any particular key? For example, if 'w' pressed called this method and if released call some other method. I solve my problem by getting "Enter" code by using ord (). key = pygame. I want to press any key and return print ('key pressed') regardless of the order in which I press. a. PySide2. The root. Jan 26, 2010 · With this code you can simultaneously press either "w" or "s" and "o" or "l" to move two paddles up and down. on_press () function to save the event of pressing any key. du pd uw yj jm jf xl ux oe kg