KeyEvent
概述
KeyEvent 类表示由按键输入交互触发的事件。KeyEvent 对象通常从 MatrixOS.KeyPad.Get() 获取,并提供对按键状态、力度、时间和其他输入属性的直接访问。
Python KeyEvent 类实现位于 Applications/Python/PikaPython/MatrixOS_KeyEvent.py,类型提示位于 Applications/Python/PikaPython/_MatrixOS_KeyEvent.pyi。
方法
ID
def ID(self) -> int
获取此按键事件的唯一标识符。
返回值:
int:按键 ID
Example:
key_event = MatrixOS.KeyPad.Get(50)
if key_event:
key_id = key_event.ID()
print(f"Key ID: {key_id}")
State
def State(self) -> int
Gets the current state of the key.
Returns:
int: Key state value
Hold
def Hold(self) -> bool
Checks if the key is being held.
Returns:
bool: True if key is held
HoldTime
def HoldTime(self) -> int
Gets the time the key has been held in milliseconds.
Returns:
int: Hold time in milliseconds
Active
def Active(self) -> bool
Checks if the key is currently active (pressed).
Returns:
bool: True if key is active
Force
def Force(self) -> float
Gets the force/pressure applied to the key.
Returns:
float: Force value (0.0 to 1.0)
Value
def Value(self, index: int = 0) -> float
Gets a specific value from the key event.
Parameters:
index(int, optional): Value index (default: 0)
Returns:
float: Value at specified index