diff --git a/hook/darwin/input_c.h b/hook/darwin/input_c.h index d884381..f045fe2 100644 --- a/hook/darwin/input_c.h +++ b/hook/darwin/input_c.h @@ -203,14 +203,12 @@ UniCharCount keycode_to_unicode(CGEventRef event_ref, UniChar *buffer, UniCharCo CFStringUppercase(keytxt, locale); CFRelease(locale); CFRelease(keytxt); - } - else { + } else { // There was an problem creating the CFMutableStringRef. count = 0; } } - } - else { + } else { // Make sure the buffer count is zero if an error occurred. count = 0; } @@ -518,8 +516,7 @@ UInt64 scancode_to_keycode(uint16_t scancode) { // Bound check 0 <= keycode < 128 if (scancode < 128) { keycode = keycode_scancode_table[scancode][1]; - } - else { + } else { // Calculate the upper offset. unsigned short i = (scancode & 0x007F) | 0x80; diff --git a/hook/darwin/properties_c.h b/hook/darwin/properties_c.h index 89559e6..9dc8ebb 100644 --- a/hook/darwin/properties_c.h +++ b/hook/darwin/properties_c.h @@ -72,8 +72,7 @@ IOHOOK_API screen_data* hook_create_screen_info(unsigned char *count) { } } } - } - else { + } else { logger(LOG_LEVEL_INFO, "%s [%u]: multiple_get_screen_info failed: %ld. Fallback.\n", __FUNCTION__, __LINE__, status); diff --git a/hook/windows/event_c.h b/hook/windows/event_c.h index c1128fc..622749b 100644 --- a/hook/windows/event_c.h +++ b/hook/windows/event_c.h @@ -118,8 +118,7 @@ IOHOOK_API void hook_post_event(iohook_event * const event) { events[events_size].ki.wScan = 0; // event->data.keyboard.keycode; events[events_size].ki.time = 0; // GetSystemTime() events_size++; - } - else { + } else { logger(LOG_LEVEL_INFO, "%s [%u]: Unable to lookup scancode: %li\n", __FUNCTION__, __LINE__, event->data.keyboard.keycode); @@ -135,8 +134,7 @@ IOHOOK_API void hook_post_event(iohook_event * const event) { events[events_size].ki.wScan = 0; // event->data.keyboard.keycode; events[events_size].ki.time = 0; // GetSystemTime() events_size++; - } - else { + } else { logger(LOG_LEVEL_INFO, "%s [%u]: Unable to lookup scancode: %li\n", __FUNCTION__, __LINE__, event->data.keyboard.keycode); diff --git a/hook/windows/hook_c.h b/hook/windows/hook_c.h index 7a10218..26cd0b2 100644 --- a/hook/windows/hook_c.h +++ b/hook/windows/hook_c.h @@ -54,8 +54,7 @@ static inline void dispatch_event(iohook_event *const event) { __FUNCTION__, __LINE__, event->type); dispatcher(event); - } - else { + } else { logger(LOG_LEVEL_WARN, "%s [%u]: No dispatch callback set!\n", __FUNCTION__, __LINE__); } @@ -113,8 +112,7 @@ static unsigned short int get_scroll_wheel_type() { SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &wheel_type, 0); if (wheel_type == WHEEL_PAGESCROLL) { value = WHEEL_BLOCK_SCROLL; - } - else { + } else { value = WHEEL_UNIT_SCROLL; } @@ -131,8 +129,7 @@ static unsigned short int get_scroll_wheel_amount() { SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &wheel_amount, 0); if (wheel_amount == WHEEL_PAGESCROLL) { value = 1; - } - else { + } else { value = (unsigned short int) wheel_amount; } @@ -303,8 +300,7 @@ LRESULT CALLBACK keyboard_hook_event_proc(int nCode, WPARAM wParam, LPARAM lPara LRESULT hook_result = -1; if (nCode < 0 || event.reserved ^ 0x01) { hook_result = CallNextHookEx(keyboard_event_hhook, nCode, wParam, lParam); - } - else { + } else { logger(LOG_LEVEL_DEBUG, "%s [%u]: Consuming the current event. (%li)\n", __FUNCTION__, __LINE__, (long) hook_result); } @@ -321,13 +317,11 @@ static void process_button_pressed(MSLLHOOKSTRUCT *mshook, uint16_t button) { if (button == click_button && (long int) (timestamp - click_time) <= hook_get_multi_click_time()) { if (click_count < USHRT_MAX) { click_count++; - } - else { + } else { logger(LOG_LEVEL_WARN, "%s [%u]: Click count overflow detected!\n", __FUNCTION__, __LINE__); } - } - else { + } else { // Reset the click count. click_count = 1; @@ -436,8 +430,7 @@ static void process_mouse_moved(MSLLHOOKSTRUCT *mshook) { if (mouse_dragged) { // Create Mouse Dragged event. event.type = EVENT_MOUSE_DRAGGED; - } - else { + } else { // Create a Mouse Moved event. event.type = EVENT_MOUSE_MOVED; } @@ -519,20 +512,17 @@ LRESULT CALLBACK mouse_hook_event_proc(int nCode, WPARAM wParam, LPARAM lParam) if (HIWORD(mshook->mouseData) == XBUTTON1) { set_modifier_mask(MASK_BUTTON4); process_button_pressed(mshook, MOUSE_BUTTON4); - } - else if (HIWORD(mshook->mouseData) == XBUTTON2) { + } else if (HIWORD(mshook->mouseData) == XBUTTON2) { set_modifier_mask(MASK_BUTTON5); process_button_pressed(mshook, MOUSE_BUTTON5); - } - else { + } else { // Extra mouse buttons. uint16_t button = HIWORD(mshook->mouseData); // Add support for mouse 4 & 5. if (button == 4) { set_modifier_mask(MOUSE_BUTTON4); - } - else if (button == 5) { + } else if (button == 5) { set_modifier_mask(MOUSE_BUTTON5); } @@ -561,20 +551,17 @@ LRESULT CALLBACK mouse_hook_event_proc(int nCode, WPARAM wParam, LPARAM lParam) if (HIWORD(mshook->mouseData) == XBUTTON1) { unset_modifier_mask(MASK_BUTTON4); process_button_released(mshook, MOUSE_BUTTON4); - } - else if (HIWORD(mshook->mouseData) == XBUTTON2) { + } else if (HIWORD(mshook->mouseData) == XBUTTON2) { unset_modifier_mask(MASK_BUTTON5); process_button_released(mshook, MOUSE_BUTTON5); - } - else { + } else { // Extra mouse buttons. uint16_t button = HIWORD(mshook->mouseData); // Add support for mouse 4 & 5. if (button == 4) { unset_modifier_mask(MOUSE_BUTTON4); - } - else if (button == 5) { + } else if (button == 5) { unset_modifier_mask(MOUSE_BUTTON5); } @@ -608,8 +595,7 @@ LRESULT CALLBACK mouse_hook_event_proc(int nCode, WPARAM wParam, LPARAM lParam) LRESULT hook_result = -1; if (nCode < 0 || event.reserved ^ 0x01) { hook_result = CallNextHookEx(mouse_event_hhook, nCode, wParam, lParam); - } - else { + } else { logger(LOG_LEVEL_DEBUG, "%s [%u]: Consuming the current event. (%li)\n", __FUNCTION__, __LINE__, (long) hook_result); } @@ -674,8 +660,7 @@ IOHOOK_API int hook_run() { if (hInst != NULL) { // Initialize native input helper functions. load_input_helper(); - } - else { + } else { logger(LOG_LEVEL_ERROR, "%s [%u]: Could not determine hInst for SetWindowsHookEx()! (%#lX)\n", __FUNCTION__, __LINE__, (unsigned long) GetLastError()); @@ -721,8 +706,7 @@ IOHOOK_API int hook_run() { TranslateMessage(&message); DispatchMessage(&message); } - } - else { + } else { logger(LOG_LEVEL_ERROR, "%s [%u]: SetWindowsHookEx() failed! (%#lX)\n", __FUNCTION__, __LINE__, (unsigned long) GetLastError()); diff --git a/hook/windows/input_c.h b/hook/windows/input_c.h index 995101a..561708a 100644 --- a/hook/windows/input_c.h +++ b/hook/windows/input_c.h @@ -315,8 +315,7 @@ unsigned short keycode_to_scancode(DWORD vk_code, DWORD flags) { scancode |= 0x0E00; break; } - } - else { + } else { // logger(LOG_LEVEL_WARN, "%s [%u]: Test2, vk_code %li\n", // __FUNCTION__, __LINE__, vk_code); } @@ -332,8 +331,7 @@ DWORD scancode_to_keycode(unsigned short scancode) { // NOTE vk_code >= 0 is assumed because the scancode is unsigned. if (scancode < 128) { keycode = keycode_scancode_table[scancode][1]; - } - else { + } else { // Calculate the upper offset based on the lower half of the scancode + 128. unsigned short int i = (scancode & 0x007F) | 0x80; @@ -431,8 +429,7 @@ static int refresh_locale_list() { logger(LOG_LEVEL_WARN, "%s [%u]: Locale size mismatch! " "Expected %i, received %i!\n", __FUNCTION__, __LINE__, hkl_size, new_size); - } - else { + } else { logger(LOG_LEVEL_INFO, "%s [%u]: Received %i locales.\n", __FUNCTION__, __LINE__, new_size); } @@ -468,8 +465,7 @@ static int refresh_locale_list() { } count++; - } - else { + } else { logger(LOG_LEVEL_DEBUG, "%s [%u]: Removing locale ID %#p from the cache.\n", __FUNCTION__, __LINE__, locale_item->id); @@ -542,8 +538,7 @@ static int refresh_locale_list() { if (locale_previous == NULL) { // If nothing came before, the list is empty. locale_first = locale_item; - } - else { + } else { // Append the new locale to the end of the list. locale_previous->next = locale_item; } @@ -557,8 +552,7 @@ static int refresh_locale_list() { locale_previous = locale_item; count++; - } - else { + } else { logger(LOG_LEVEL_ERROR, "%s [%u]: GetProcAddress() failed for KbdLayerDescriptor!\n", __FUNCTION__, __LINE__); @@ -567,22 +561,19 @@ static int refresh_locale_list() { free(locale_item); locale_item = NULL; } - } - else { + } else { logger(LOG_LEVEL_ERROR, "%s [%u]: GetSystemDirectory() failed!\n", __FUNCTION__, __LINE__); } - } - else { + } else { logger(LOG_LEVEL_ERROR, "%s [%u]: Could not find keyboard map for locale %#p!\n", __FUNCTION__, __LINE__, hkl_list[i]); } } } - } - else { + } else { logger(LOG_LEVEL_ERROR, "%s [%u]: GetKeyboardLayoutList() failed!\n", __FUNCTION__, __LINE__); @@ -627,8 +618,7 @@ SIZE_T keycode_to_unicode(DWORD keycode, PWCHAR buffer, SIZE_T size) { // If they layout changes the dead key state needs to be reset. // This is consistent with the way Windows handles locale changes. deadChar = WCH_NONE; - } - else { + } else { logger(LOG_LEVEL_DEBUG, "%s [%u]: Refreshing locale cache.\n", __FUNCTION__, __LINE__); @@ -669,11 +659,9 @@ SIZE_T keycode_to_unicode(DWORD keycode, PWCHAR buffer, SIZE_T size) { if (state & ~SHRT_MAX) { if (pVkToBit[i].Vk == VK_SHIFT) { is_shift = true; - } - else if (pVkToBit[i].Vk == VK_CONTROL) { + } else if (pVkToBit[i].Vk == VK_CONTROL) { is_ctrl = true; - } - else if (pVkToBit[i].Vk == VK_MENU) { + } else if (pVkToBit[i].Vk == VK_MENU) { is_alt = true; } } @@ -720,8 +708,7 @@ SIZE_T keycode_to_unicode(DWORD keycode, PWCHAR buffer, SIZE_T size) { if ((((PVK_TO_WCHARS) pCurrentVkToWchars)->Attributes == CAPLOK) && capsLock) { if (is_shift && mod > 0) { mod -= 1; - } - else { + } else { mod += 1; } } @@ -739,8 +726,7 @@ SIZE_T keycode_to_unicode(DWORD keycode, PWCHAR buffer, SIZE_T size) { // No previous dead key was set so cache the next // wchar so we know what to do next time its pressed. deadChar = ((PVK_TO_WCHARS) pCurrentVkToWchars)->wch[mod]; - } - else { + } else { if (size >= 2) { // Received a second dead key. memset(buffer, deadChar, 2); @@ -751,8 +737,7 @@ SIZE_T keycode_to_unicode(DWORD keycode, PWCHAR buffer, SIZE_T size) { charCount = 2; } } - } - else if (unicode != WCH_NONE) { + } else if (unicode != WCH_NONE) { // We are not WCH_NONE or WCH_DEAD if (size >= 1) { buffer[0] = unicode; @@ -761,8 +746,7 @@ SIZE_T keycode_to_unicode(DWORD keycode, PWCHAR buffer, SIZE_T size) { } break; - } - else { + } else { // Add sizeof WCHAR because we are really an array of WCHAR[n] not WCHAR[] pCurrentVkToWchars += sizeof(VK_TO_WCHARS) + (sizeof(WCHAR) * n); } diff --git a/hook/windows/properties_c.h b/hook/windows/properties_c.h index c9f2c74..c66930c 100644 --- a/hook/windows/properties_c.h +++ b/hook/windows/properties_c.h @@ -40,8 +40,7 @@ static BOOL CALLBACK monitor_enum_proc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT if (screens->data == NULL) { screens->data = (screen_data *) malloc(sizeof(screen_data)); - } - else { + } else { screens->data = (screen_data *) realloc(screens, sizeof(screen_data) * screens->count); }