Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6d4dc8b

Browse files
committed
added controlling keyboard tutorial
1 parent7ce7e62 commit6d4dc8b

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
2828
-[How to Transfer Files in the Network using Sockets in Python](https://www.thepythoncode.com/article/send-receive-files-using-sockets-python). ([code](general/transfer-files/))
2929
-[How to Get Hardware and System Information in Python](https://www.thepythoncode.com/article/get-hardware-system-information-python). ([code](general/sys-info))
3030
-[How to Control your Mouse in Python](https://www.thepythoncode.com/article/control-mouse-python). ([code](general/mouse-controller))
31+
-[How to Control your Keyboard in Python](https://www.thepythoncode.com/article/control-keyboard-python). ([code](general/keyboard-controller))
3132

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[How to Control your Keyboard in Python](https://www.thepythoncode.com/article/control-keyboard-python)
2+
To make this work:
3+
- pip3 install -r requirements.txt
4+
5+
And run the lines of code in`control_keyboard.py` individually, that's because it makes no sense to run them at once.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
importkeyboard
2+
3+
# registering a hotkey that replaces one typed text with another
4+
# replaces every "@email" followed by a space with my actual email
5+
keyboard.add_abbreviation("@email","rockikz@thepythoncode.com")
6+
7+
# invokes a callback everytime a hotkey is pressed
8+
keyboard.add_hotkey("ctrl+alt+p",lambda:print("CTRL+ALT+P Pressed!"))
9+
10+
# check if a ctrl is pressed
11+
print(keyboard.is_pressed('ctrl'))
12+
13+
# press space
14+
keyboard.send("space")
15+
16+
# sends artificial keyboard events to the OS
17+
# simulating the typing of a given text
18+
# setting 0.1 seconds to wait between keypresses to look fancy
19+
keyboard.write("Python Programming is always fun!",delay=0.1)
20+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
keyboard

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp