1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python でキーボードイベントを確認するための簡単な方法

Last updated at Posted at 2022-03-11

keyboard https://github.com/boppreh/keyboard を使います。

上のリンクと下のコードだけでわかると思いますが、需要があれば解説を足します。

pip install keyboard

python -m keyboard

実行例

{"event_type": "down", "scan_code": 16, "name": "q", "time": 1646975615.8746192, "is_keypad": false}
q{"event_type": "up", "scan_code": 16, "name": "q", "time": 1646975615.9862385, "is_keypad": false}
{"event_type": "down", "scan_code": 42, "name": "shift", "time": 1646975617.9866295, "is_keypad": false}
{"event_type": "up", "scan_code": 42, "name": "shift", "time": 1646975618.059266, "is_keypad": false}
{"event_type": "down", "scan_code": 54, "name": "right shift", "time": 1646975621.0223727, "is_keypad": false}
{"event_type": "up", "scan_code": 54, "name": "right shift", "time": 1646975621.0913706, "is_keypad": false}
{"event_type": "down", "scan_code": 29, "name": "right ctrl", "time": 1646975624.3792064, "is_keypad": false}
{"event_type": "up", "scan_code": 29, "name": "right ctrl", "time": 1646975624.4272087, "is_keypad": false}
{"event_type": "down", "scan_code": 28, "name": "enter", "time": 1646975626.379538, "is_keypad": false}

最後の Enter で抜けています。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?