add esc support fix #105

This commit is contained in:
vcaesar 2018-01-27 18:36:16 +08:00
parent b9836d769a
commit 9503875953
2 changed files with 25 additions and 16 deletions

View File

@ -30,30 +30,38 @@ void dispatch_proc(iohook_event * const event) {
case EVENT_KEY_PRESSED: case EVENT_KEY_PRESSED:
// If the escape key is pressed, naturally terminate the program. // If the escape key is pressed, naturally terminate the program.
if (event->data.keyboard.keycode == VC_ESCAPE) { if (event->data.keyboard.keycode == VC_ESCAPE) {
int status = hook_stop(); // int status = hook_stop();
switch (status) { // switch (status) {
// System level errors. // // System level errors.
case IOHOOK_ERROR_OUT_OF_MEMORY: // case IOHOOK_ERROR_OUT_OF_MEMORY:
loggerProc(LOG_LEVEL_ERROR, "Failed to allocate memory. (%#X)", status); // loggerProc(LOG_LEVEL_ERROR, "Failed to allocate memory. (%#X)", status);
break; // break;
case IOHOOK_ERROR_X_RECORD_GET_CONTEXT: // case IOHOOK_ERROR_X_RECORD_GET_CONTEXT:
// NOTE This is the only platform specific error that occurs on hook_stop(). // // NOTE This is the only platform specific error that occurs on hook_stop().
loggerProc(LOG_LEVEL_ERROR, "Failed to get XRecord context. (%#X)", status); // loggerProc(LOG_LEVEL_ERROR, "Failed to get XRecord context. (%#X)", status);
break; // break;
// Default error. // // Default error.
case IOHOOK_FAILURE: // case IOHOOK_FAILURE:
default: // default:
loggerProc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status); // loggerProc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
break; // break;
} // }
} }
case EVENT_KEY_RELEASED: case EVENT_KEY_RELEASED:
snprintf(buffer + length, sizeof(buffer) - length, snprintf(buffer + length, sizeof(buffer) - length,
",keycode=%u,rawcode=0x%X", ",keycode=%u,rawcode=0x%X",
event->data.keyboard.keycode, event->data.keyboard.rawcode); event->data.keyboard.keycode, event->data.keyboard.rawcode);
int akeyCode = (uint16_t) event->data.keyboard.keycode; int akeyCode = (uint16_t) event->data.keyboard.keycode;
if (event->data.keyboard.keycode == VC_ESCAPE
&& atoi(cevent) == 11) {
int stopEvent = stop_event();
// printf("stop_event%d\n", stopEvent);
cstatus = 0;
}
// printf("atoi(str)---%d\n", atoi(cevent)); // printf("atoi(str)---%d\n", atoi(cevent));
if (akeyCode == atoi(cevent)){ if (akeyCode == atoi(cevent)){
int stopEvent = stop_event(); int stopEvent = stop_event();

View File

@ -1111,6 +1111,7 @@ func AddEvent(aeve string) int {
"f11": "69", "f11": "69",
"f12": "70", "f12": "70",
// more // more
"esc": "11",
"tab": "15", "tab": "15",
"ctrl": "29", "ctrl": "29",
"control": "29", "control": "29",