diff --git a/src/keyboard_control.cpp b/src/keyboard_control.cpp index d6b68cbfa..fa1594978 100644 --- a/src/keyboard_control.cpp +++ b/src/keyboard_control.cpp @@ -882,3 +882,9 @@ bool keycontrol_register_key(struct module *receiver_mod, int64_t key, const cha return true; } +void get_keycode_name(int64_t ch, char *buf, size_t buflen) { + string name = get_keycode_representation(ch); + strncpy(buf, name.c_str(), buflen - 1); + buf[buflen - 1] = '\0'; +} + diff --git a/src/keyboard_control.h b/src/keyboard_control.h index bcea11a4c..0e3a9cb72 100644 --- a/src/keyboard_control.h +++ b/src/keyboard_control.h @@ -110,10 +110,13 @@ private: #define K_LEFT 0x1b5b44 #define K_CTRL(x) (1 + tolower(x) - 'a') +#define MAX_KEYCODE_NAME_LEN 64 + // attribute used guaranties that the symbol is present even if not referenced (modular build) /// @todo all UG core functions should have the 'used' attribute EXTERN_C void keycontrol_send_key(struct module *root, int64_t key) ATTRIBUTE(used); EXTERN_C bool keycontrol_register_key(struct module *sender_mod, int64_t key, const char *message, const char *description) ATTRIBUTE(used); +EXTERN_C void get_keycode_name(int64_t ch, char *buf, size_t buflen) ATTRIBUTE(used); #endif // keyboard_control_h_