maix::peripheral::key

maix.peripheral.key module

This is maix::peripheral::key module of MaixCDK.
All of these elements are in namespace maix::peripheral::key.

For MaixCDK developer: DO NOT edit this doc file manually, this doc is auto generated!

Module

No module

Enum

Keys

Keys enum, id the same as linux input.h(input-event-codes.h)

item describe
values KEY_NONE:
KEY_ESC:
KEY_POWER:
KEY_OK:
KEY_OPTION:
KEY_NEXT:
KEY_PREV:

C++ defination code:

enum Keys{
        KEY_NONE   = 0x000,
        KEY_ESC    = 0x001,
        KEY_POWER  = 0x074,
        KEY_OK     = 0x160,
        KEY_OPTION = 0x165,
        KEY_NEXT   = 0x197,
        KEY_PREV   = 0x19c,
    }

State

Key state enum

item describe
values KEY_RELEASED:
KEY_PRESSED:
KEY_LONG_PRESSED:

C++ defination code:

enum State{
        KEY_RELEASED     = 0,
        KEY_PRESSED      = 1,
        KEY_LONG_PRESSED = 2,
    }

Variable

Function

add_default_listener

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

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

Key input class

C++ defination code:

class Key

Key

Key Device constructor

item description
type func
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.
device: Specifies the input device to use. The default initializes all keys,
for a specific device, provide the path (e.g., "/dev/input/device").
long_press_time: The duration (in milliseconds) from pressing the key to triggering the long press event. Default is 2000ms.
static False

C++ defination code:

Key(std::function<void(int, int)> callback = nullptr, bool open = true, const string &device = "", int long_press_time = 2000)

open

Open(Initialize) key device, if already opened, will close first and then open.

item description
type func
return err::Err type, err.Err.ERR_NONE means success
static False

C++ defination code:

err::Err open()

close

Close key device

item description
type func
return err::Err type, err.Err.ERR_NONE means success
static False

C++ defination code:

err::Err close()

is_opened

Check key device is opened

item description
type func
return bool type, true means opened, false means closed
static False

C++ defination code:

bool is_opened()

read

Read key input, if callback is set, DO NOT call this function manually.

item description
type func
param key: maix.key.Keys type, indicate which key is triggered, e.g. maix.key.Keys.KEY_OK mean the OK key is triggered.
If read failed, will not change the value of key.
value: maix.key.State type, indicate the key state, e.g. maix.key.State.KEY_PRESSED mean the key is pressed
If read failed, will not change the value of value.
return err::Err type, err.Err.ERR_NONE means success, err.Err.ERR_NOT_READY means no key input, other means error.
static False

C++ defination code:

err::Err read(int &key, int &value)

read (overload 1)

Read key input, and return key and value, if callback is set, DO NOT call this function manually.

item description
type func
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()

long_press_time

Sets and retrieves the key's long press time.

item description
type func
param press_time: The long press time to set for the key.
Setting it to 0 will disable the long press event.
return int type, the current long press time for the key (in milliseconds).
static False

C++ defination code:

int long_press_time(int press_time = -1)