Skip to content
Back to skills

Python键盘监听与按键信息提取

ASecurity

使用pynput库监听键盘事件,提取按键的虚拟键码(code)和名称(name),并返回标准化的字典格式。

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationpython

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill 'python键盘监听与按键信息提取' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python键盘监听与按键信息提取?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Python键盘监听与按键信息提取
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-python-b941a509/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-python-b941a509)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "7c7a874b-fb7e-4069-812a-33a49d91a3cb"
name: "Python键盘监听与按键信息提取"
description: "使用pynput库监听键盘事件,提取按键的虚拟键码(code)和名称(name),并返回标准化的字典格式。"
version: "0.1.0"
tags:
  - "python"
  - "pynput"
  - "keyboard"
  - "监听"
  - "按键提取"
triggers:
  - "python监听按键"
  - "获取按键code和name"
  - "pynput监听键盘"
  - "python键盘事件监听"
---

# 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
1. **Library Usage**: Use `pynput.keyboard` for monitoring.
2. **Key Name Extraction**: Implement a function `get_key_name(key)` that returns `key.char` if `isinstance(key, keyboard.KeyCode)`, otherwise returns `key.name`.
3. **Key Code Extraction**: Implement a function `get_key_code(key)` that attempts to return `key.value.vk`. If an `AttributeError` occurs, it should return `key.vk`.
4. **Data Structure**: In the `on_press` callback, use the extraction functions to obtain the code and name. The output should be a dictionary format: `{"code": code, "name": name}`.
5. **Exit Mechanism**: To stop the listener, return `False` within the callback function (e.g., when the Esc key is pressed).

# Anti-Patterns
- Do not use `key.vk` directly without handling the `AttributeError` for special keys.
- Do not assume all keys have a `char` attribute; distinguish between `KeyCode` and `Key` objects.

## Triggers

- python监听按键
- 获取按键code和name
- pynput监听键盘
- python键盘事件监听

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.