⌨️ Klavye Yönetimi
Python ile klavye ve mouse yönetimi (keyboard and mouse hooks), kısayol oluşturma, tuş basımı ve mouse tıklamaları

💞 Kısayol Ekleme

    👮‍♂️ suppress deyimi ile hotkey tetiklendiğinde tuş basımlarını göndermezsin
1
print('Press and release your desired shortcut: ')
2
shortcut = keyboard.read_hotkey()
3
print('Shortcut selected:', shortcut)
4
5
6
def on_triggered():
7
print("Triggered!")
8
9
10
keyboard.add_hotkey(shortcut, on_triggered, suppress=True)
11
12
print("Press ESC to stop.")
13
keyboard.wait('esc')
14
Copied!

🔴 Tekrarlama

    👂 Klavye eylemlerini dinler
    🔄 Dinleme işlemi bittiği zaman tüm eylemleri aynı sırayla tekrarlar
1
import keyboard
2
import time
3
4
keyboard.start_recording()
5
6
time.sleep(10)
7
8
events = keyboard.stop_recording()
9
keyboard.replay(events)
10
Copied!

👁️ Tuş Basımlarını Algılama

1
import keyboard
2
import sys
3
sys.path.append('..')
4
5
6
def print_pressed_keys(e):
7
line = ', '.join(str(code) for code in keyboard._pressed_events)
8
# '\r' and end='' overwrites the previous line.
9
# ' '*40 prints 40 spaces at the end to ensure the previous line is cleared.
10
print('\r' + line + ' '*40, end='')
11
12
13
keyboard.hook(print_pressed_keys)
14
keyboard.wait()
15
Copied!

📜 Tuş Basımlarını Raporlama

1
import sys
2
sys.path.append('..')
3
4
# Also available as just `python -m keyboard`.
5
from keyboard import __main__
6
7
# {"event_type": "down", "name": "a", "scan_code": 30, "time": 1491442622.6348252}
8
# {"event_type": "down", "name": "s", "scan_code": 31, "time": 1491442622.664881}
9
# {"event_type": "down", "name": "d", "scan_code": 32, "time": 1491442622.7148278}
10
# {"event_type": "down", "name": "f", "scan_code": 33, "time": 1491442622.7544951}
11
# {"event_type": "up", "name": "a", "scan_code": 30, "time": 1491442622.7748237}
12
# {"event_type": "up", "name": "s", "scan_code": 31, "time": 1491442622.825077}
13
# {"event_type": "up", "name": "d", "scan_code": 32, "time": 1491442622.8644736}
14
# {"event_type": "up", "name": "f", "scan_code": 33, "time": 1491442622.9056144}
15
Copied!

✍ Verilen Yazıyı Tekrarlama

1
import fileinput
2
import keyboard
3
import sys
4
sys.path.append('../')
5
6
for line in fileinput.input():
7
keyboard.write(line)
Copied!

🔗 Faydalı Bağlantılar

GitHub - boppreh/keyboard: Hook and simulate global keyboard events on Windows and Linux.
GitHub
Last modified 1yr ago