Python键盘监听与按键信息提取
Skill ECNU-ICALK/AutoSkill/SkillBank/Users/chinese_gpt3.5_8_GLM4.7/python键盘监听与按键信息提取
使用pynput库监听键盘事件,提取按键的虚拟键码(code)和名称(name),并返回标准化的字典格式。From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill python键盘监听与按键信息提取Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
1.9 KB, 369 tokens by cl100k_base, as published. Nobody here has run it
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
pynput.keyboardfor monitoring. - Key Name Extraction: Implement a function
get_key_name(key)that returnskey.charifisinstance(key, keyboard.KeyCode), otherwise returnskey.name. - Key Code Extraction: Implement a function
get_key_code(key)that attempts to returnkey.value.vk. If anAttributeErroroccurs, it should returnkey.vk. - Data Structure: In the
on_presscallback, use the extraction functions to obtain the code and name. The output should be a dictionary format:{"code": code, "name": name}. - Exit Mechanism: To stop the listener, return
Falsewithin the callback function (e.g., when the Esc key is pressed).
Anti-Patterns
- Do not use
key.vkdirectly without handling theAttributeErrorfor special keys. - Do not assume all keys have a
charattribute; distinguish betweenKeyCodeandKeyobjects.
Triggers
- python监听按键
- 获取按键code和name
- pynput监听键盘
- python键盘事件监听
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.