@@ -403,9 +403,8 @@ static inline void process_mouse_moved(uint64_t timestamp, MSLLHOOKSTRUCT *mshoo
403403
404404 event .mask = get_modifiers ();
405405
406- // Check the upper half of the current modifiers for non zero
407- // value. This indicates the presence of a button down mask.
408- bool mouse_dragged = (event .mask >> 8 > 0 );
406+ // Check the modifier mask range for MASK_BUTTON1 - 5.
407+ bool mouse_dragged = event .mask & (MASK_BUTTON1 | MASK_BUTTON2 | MASK_BUTTON3 | MASK_BUTTON4 | MASK_BUTTON5 );
409408 if (mouse_dragged ) {
410409 // Create Mouse Dragged event.
411410 event .type = EVENT_MOUSE_DRAGGED ;
@@ -450,10 +449,10 @@ static inline void process_mouse_wheel(uint64_t timestamp, MSLLHOOKSTRUCT *mshoo
450449 event .data .wheel .amount = get_scroll_wheel_amount ();
451450
452451 /* Delta HIWORD(mshook->mouseData)
453- * A positive value indicates that the wheel was rotated
454- * forward, away from the user; a negative value indicates that
455- * the wheel was rotated backward, toward the user. One wheel
456- * click is defined as WHEEL_DELTA, which is 120. */
452+ * A positive value indicates that the wheel was rotated
453+ * forward, away from the user; a negative value indicates that
454+ * the wheel was rotated backward, toward the user. One wheel
455+ * click is defined as WHEEL_DELTA, which is 120. */
457456 event .data .wheel .rotation = ((int16_t ) HIWORD (mshook -> mouseData ) / WHEEL_DELTA ) * -1 ;
458457
459458 logger (LOG_LEVEL_INFO , "%s [%u]: Mouse wheel type %u, rotated %i units at %u, %u.\n" ,
@@ -499,8 +498,12 @@ LRESULT CALLBACK mouse_hook_event_proc(int nCode, WPARAM wParam, LPARAM lParam)
499498 // Extra mouse buttons.
500499 uint16_t button = HIWORD (mshook -> mouseData );
501500
502- if (button + 7 < 16 ) {
503- set_modifier_mask (1 << (button + 7 ));
501+ // Add support for mouse 4 & 5.
502+ if (button == 4 ) {
503+ set_modifier_mask (MOUSE_BUTTON4 );
504+ }
505+ else if (button == 5 ) {
506+ set_modifier_mask (MOUSE_BUTTON5 );
504507 }
505508
506509 process_button_pressed (timestamp , mshook , button );
@@ -537,8 +540,12 @@ LRESULT CALLBACK mouse_hook_event_proc(int nCode, WPARAM wParam, LPARAM lParam)
537540 // Extra mouse buttons.
538541 uint16_t button = HIWORD (mshook -> mouseData );
539542
540- if (button + 7 < 16 ) {
541- unset_modifier_mask (1 << (button + 7 ));
543+ // Add support for mouse 4 & 5.
544+ if (button == 4 ) {
545+ unset_modifier_mask (MOUSE_BUTTON4 );
546+ }
547+ else if (button == 5 ) {
548+ unset_modifier_mask (MOUSE_BUTTON5 );
542549 }
543550
544551 process_button_released (timestamp , mshook , MOUSE_BUTTON5 );
@@ -688,8 +695,7 @@ UIOHOOK_API int hook_run() {
688695
689696 // Block until the thread receives an WM_QUIT request.
690697 MSG message ;
691- //while (GetMessage(&message, (HWND) -1, 0, 0) > 0) {
692- while (GetMessage (& message , (HWND ) 0 , 0 , 0 ) > 0 ) {
698+ while (GetMessage (& message , (HWND ) NULL , 0 , 0 ) > 0 ) {
693699 TranslateMessage (& message );
694700 DispatchMessage (& message );
695701 }
0 commit comments