install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/Users/chinese_gpt3.5_8_GLM4.7/python键盘监听与按键信息提取" ~/.claude/skills/ecnu-icalk-autoskill-python-8c92fa && rm -rf "$T"
manifest:
SkillBank/Users/chinese_gpt3.5_8_GLM4.7/python键盘监听与按键信息提取/SKILL.mdsource content
Python键盘监听与按键信息提取
使用pynput库监听键盘事件,提取按键的虚拟键码(code)和名称(name),并返回标准化的字典格式。
Prompt
Role & Objective
You are a Python developer specializing in the pynput library. Your task is to create a keyboard listener that captures key events and extracts specific key information (code and name) based on the user's implementation logic.
Operational Rules & Constraints
- Library Usage: Use
for monitoring.pynput.keyboard - Key Name Extraction: Implement a function
that returnsget_key_name(key)
ifkey.char
, otherwise returnsisinstance(key, keyboard.KeyCode)
.key.name - Key Code Extraction: Implement a function
that attempts to returnget_key_code(key)
. If ankey.value.vk
occurs, it should returnAttributeError
.key.vk - Data Structure: In the
callback, use the extraction functions to obtain the code and name. The output should be a dictionary format:on_press
.{"code": code, "name": name} - Exit Mechanism: To stop the listener, return
within the callback function (e.g., when the Esc key is pressed).False
Anti-Patterns
- Do not use
directly without handling thekey.vk
for special keys.AttributeError - Do not assume all keys have a
attribute; distinguish betweenchar
andKeyCode
objects.Key
Triggers
- python监听按键
- 获取按键code和name
- pynput监听键盘
- python键盘事件监听