
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Keyboard Module in Python
In this article, we will learn about the use of the Keyboard module in Python 3.x. Or earlier.
Ide preferred − Jupyter notebook
Installation −
>>> pip install keyboard
Functionalities of the module −
- Allows us to block the action of specific keys
- We can manage intents from the keyboard using on click listeners.
- Cross-platform compatibility.
- Supports special & hotkeys available on the keyboard.
Now let’s implement this in the form of code −
Example
import keyboard # It writes the content keyboard.write("Tutorialspoint\n") # It writes end of line keyboard.press_and_release('shift + o, shift + y, \n') keyboard.press_and_release('k, j') # it blocks until ctrl keyboard.wait('Ctrl')
Output
Tutorialspoint O Y k j
Example
import keyboard # It writes the content keyboard.write("tutor\n") # It writes end of line keyboard.press_and_release('shift + a, shift + w, \n') keyboard.press_and_release('q, u') # it blocks until enter keyboard.wait('Enter')
Output
tutor A W q u
We can also use the record and the play method available in the keyboard module that can be directly imported into the console. In this way, we can also record keyboard activities. To know more details you may refer to https://pypi.org/project/keyboard/
Conclusion
In this article, we will learn about the application of the keyboard module in Python 3.x. Or earlier.
Advertisements