maix.peripheral.key
maix.peripheral.key module
You can use
maix.peripheral.keyto access this module with MaixPy
This module is generated from MaixCDK
Module
No module
Enum
Keys
| item | doc |
|---|---|
| brief | Keys enum, id the same as linux input.h(input-event-codes.h) |
| values | KEY_NONE: KEY_ESC: KEY_OK: KEY_OPTION: KEY_NEXT: KEY_PREV: |
C++ defination code:
enum Keys{
KEY_NONE = 0x000,
KEY_ESC = 0x001,
KEY_OK = 0x160,
KEY_OPTION = 0x165,
KEY_NEXT = 0x197,
KEY_PREV = 0x19c
}
State
| item | doc |
|---|---|
| brief | Key state enum |
| values | KEY_RELEASED: KEY_PRESSED: |
C++ defination code:
enum State{
KEY_RELEASED = 0,
KEY_PRESSED = 1,
}
Variable
Function
add_default_listener
| item | doc |
|---|---|
| brief | Add default listener, if you want to exit app when press ok button, you can just call this function.\nThis function is auto called in MaixPy' startup code, so you don't need to call it in MaixPy.\nCreate Key object will auto call rm_default_listener() to cancel the default ok button function.\nWhen ok button pressed, a SIGINT signal will be raise and call app.set_exit_flag(True). |
C++ defination code:
void add_default_listener()
rm_default_listener
| item | doc |
|---|---|
| brief | Remove default listener, if you want to cancel the default ok button function(exit app), you can just call this function. |
C++ defination code:
void rm_default_listener()
Class
Key
| item | doc |
|---|---|
| brief | Key input class |
C++ defination code:
class Key
__init__
def __init__(self, callback: typing.Callable[[int, int], None] = None, open: bool = True) -> None
| item | doc |
|---|---|
| type | func |
| brief | Key Device constructor |
| param | callback: When key triggered and callback is not empty(empty In MaixPy is None, in C++ is nullptr), callback will be called with args key(key.Keys) and value(key.State). If set to null, you can get key value by read() function. This callback called in a standalone thread, so you can block a while in callback, and you should be carefully when operate shared data. open: auto open device in constructor, if false, you need call open() to open device |
| static | False |
C++ defination code:
Key(std::function<void(int, int)> callback = nullptr, bool open = true)
open
def open(self) -> maix.err.Err
| item | doc |
|---|---|
| type | func |
| brief | Open(Initialize) key device, if already opened, will close first and then open. |
| return | err::Err type, err.Err.ERR_NONE means success |
| static | False |
C++ defination code:
err::Err open()
close
def close(self) -> maix.err.Err
| item | doc |
|---|---|
| type | func |
| brief | Close key device |
| return | err::Err type, err.Err.ERR_NONE means success |
| static | False |
C++ defination code:
err::Err close()
is_opened
def is_opened(self) -> bool
| item | doc |
|---|---|
| type | func |
| brief | Check key device is opened |
| return | bool type, true means opened, false means closed |
| static | False |
C++ defination code:
bool is_opened()
read
def read(self) -> tuple[int, int]
| item | doc |
|---|---|
| type | func |
| brief | Read key input, and return key and value, if callback is set, DO NOT call this function manually. |
| return | list type, first is key(maix.key.Keys), second is value(maix.key.State), if no key input, return [0, 0] |
| throw | If read failed, will throw maix.err.Exception. |
| static | False |
C++ defination code:
std::pair<int, int> read()