Keycontrol: function to obtain key name

This commit is contained in:
Martin Pulec
2019-11-04 10:35:17 +01:00
parent 7693b3e1e5
commit e52874998c
2 changed files with 9 additions and 0 deletions

View File

@@ -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';
}

View File

@@ -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_