From 166056799c20ec66cdf94124e8c8cb3ef8114c84 Mon Sep 17 00:00:00 2001 From: Michał Cichoń Date: Fri, 3 May 2019 16:57:20 +0200 Subject: Add support for hotkeys. #20 Hotkeys can be assigned to action in configuration file ex: hk_ = g + shift + alt + ctrl --- src/ui_readline.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/ui_readline.c') diff --git a/src/ui_readline.c b/src/ui_readline.c index 5d6b7a7..687258a 100644 --- a/src/ui_readline.c +++ b/src/ui_readline.c @@ -75,6 +75,8 @@ static inline int BarReadlineEncodeUtf8 (int codePoint, char* utf8) { struct _BarReadline_t { DWORD DefaultAttr; + BarVirtualKeyHandler VirtualKeyHandler; + void *VirtualKeyHandlerUserData; }; void BarReadlineInit(BarReadline_t* rl) { @@ -85,6 +87,11 @@ void BarReadlineInit(BarReadline_t* rl) { void BarReadlineDestroy(BarReadline_t rl) { } +void BarReadlineSetVirtualKeyHandler(BarReadline_t rl, BarVirtualKeyHandler handler, void *ud) { + rl->VirtualKeyHandler = handler; + rl->VirtualKeyHandlerUserData = ud; +} + /* return size of previous UTF-8 character */ static size_t BarReadlinePrevUtf8 (char *ptr) { @@ -248,16 +255,11 @@ size_t BarReadline (char *buf, const size_t bufSize, const char *mask, char encodedCodePoint[5]; int encodedCodePointLength; - /* - if (keyCode == VK_MEDIA_PLAY_PAUSE) { - codePoint = 'p'; - PlaySoundA("SystemNotification", NULL, SND_ASYNC); - } - else if (keyCode == VK_MEDIA_NEXT_TRACK) { - codePoint = 'n'; - PlaySoundA("SystemNotification", NULL, SND_ASYNC); + if (input->VirtualKeyHandler != NULL) { + int newCodePoint = input->VirtualKeyHandler(keyCode, input->VirtualKeyHandlerUserData); + if (newCodePoint != 0) + codePoint = newCodePoint; } - */ if (codePoint <= 0x1F) break; -- cgit v1.2.3