Keyboard module in Python Last Updated : 12 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Python provides a library named keyboard which is used to get full control of the keyboard. It's a small Python library which can hook global events, register hotkeys, simulate key presses and much more. It helps to enter keys, record the keyboard activities and block the keys until a specified key is entered and simulate the keys.It captures all keys, even onscreen keyboard events are also captured.Keyboard module supports complex hotkeys.Using this module we can listen and send keyboard events.It works on both windows and linux operating system.Installation:To install the keyboard module, run the following command:pip install keyboardExamples of Keyboard ModuleExample 1: Simulating Key Presses and Blocking KeysThis code demonstrates how to simulate key presses and block the execution until a specific key is pressed using the keyboard module. Python import keyboard keyboard.write("GEEKS FOR GEEKS\n") keyboard.press_and_release('shift + r, shift + k, \n') keyboard.press_and_release('R, K') keyboard.wait('Ctrl') Output:GEEKS FOR GEEKS RKrkExplanation:keyboard.write() writes the text "GEEKS FOR GEEKS" to the output.keyboard.press_and_release() simulates pressing and releasing the 'Shift + R', 'Shift + K', and 'Enter' keys.keyboard.wait() pauses the program execution and waits until the 'Ctrl' key is pressed to proceed.Example 2: Using Hotkeys with Keyboard ModuleThis code shows how to use hotkeys with the keyboard module to trigger actions when specific keys or key combinations are pressed. Python import keyboard keyboard.add_hotkey('a', lambda: keyboard.write('Geek')) keyboard.add_hotkey('ctrl + shift + a', print, args =('you entered', 'hotkey')) keyboard.wait('esc') OutputaGeekyou entered hotkeyExplanation:keyboard.add_hotkey() assigns the action of writing "Geek" when the 'a' key is pressed.A second hotkey (ctrl + shift + a) prints a message when pressed.keyboard.wait('esc') pauses the program until the 'Esc' key is pressed, terminating the program.Example 3: Recording and Playing Key EventsThis code demonstrates how to record and replay key presses using the keyboard module. Python import keyboard rk = keyboard.record(until ='Esc') keyboard.play(rk, speed_factor = 1) Outputwww.geeksforgeeks.org Explanation:keyboard.record() records all key presses until the 'Esc' key is pressed.keyboard.play() replays the recorded key events at normal speed (speed_factor = 1). Comment More infoAdvertise with us Next Article Keyboard module in Python B bestharadhakrishna Follow Improve Article Tags : Technical Scripter Python Technical Scripter 2018 Python-Library Practice Tags : python Similar Reads Keyword Module in Python Python provides an in-built module keyword that allows you to know about the reserved keywords of python. The keyword module allows you the functionality to know about the reserved words or keywords of Python and to check whether the value of a variable is a reserved word or not. In case you are una 2 min read Keywords in Python | Set 2 Python Keywords - Introduction Keywords in Python | Set 1 More keywords:16. try : This keyword is used for exception handling, used to catch the errors in the code using the keyword except. Code in "try" block is checked, if there is any type of error, except block is executed. 17. except : As expl 4 min read Python VLC MediaPlayer â Enabling Keyboard Input In this article, we will see how we can enable keyboard input handling the MediaPlayer object in the python vlc module. VLC media player is a free and open-source portable cross-platform media player software and streaming media server developed by the VideoLAN project. MediaPlayer object is the bas 2 min read Python EasyGUI module - Introduction EasyGUI is a module for very simple, very easy GUI programming in Python. EasyGUI is different from other GUI generators in that EasyGUI is NOT event-driven. Instead, all GUI interactions are invoked by simple function calls. Unlike other complicated GUI's EasyGUI is the simplest GUI till now. Insta 2 min read Python Introduction Python was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code.Key Features of PythonPythonâs simple and readable syntax makes it beginner-frien 3 min read Like