@@ -102,6 +102,7 @@ static dispatcher_t dispatcher = NULL;
102
102
103
103
static unsigned short int grab_keyboard_event = 0x00 ;
104
104
static unsigned short int grab_mouse_click_event = 0x00 ;
105
+ static unsigned short int grab_mouse_move_event = 0x00 ;
105
106
106
107
UIOHOOK_API void hook_set_dispatch_proc (dispatcher_t dispatch_proc ) {
107
108
logger (LOG_LEVEL_DEBUG , "%s [%u]: Setting new dispatch callback to %#p.\n" ,
@@ -877,7 +878,7 @@ static inline void process_mouse_moved(uint64_t timestamp, CGEventRef event_ref)
877
878
878
879
// Populate mouse motion event.
879
880
event .time = timestamp ;
880
- event .reserved = 0x00 ;
881
+ event .reserved = grab_mouse_move_event ;
881
882
882
883
if (mouse_dragged ) {
883
884
event .type = EVENT_MOUSE_DRAGGED ;
@@ -1071,10 +1072,19 @@ CGEventRef hook_event_proc(CGEventTapProxy tap_proxy, CGEventType type, CGEventR
1071
1072
case kCGEventMouseMoved :
1072
1073
// Set the mouse dragged flag.
1073
1074
mouse_dragged = false;
1075
+ // CGDisplayHideCursor(kCGDirectMainDisplay);;
1076
+ // CGDisplayShowCursor(kCGDirectMainDisplay);;
1074
1077
process_mouse_moved (timestamp , event_ref );
1078
+ if (event .reserved ) {
1079
+ int32_t deltaX , deltaY ;
1080
+ CGGetLastMouseDelta (& deltaX , & deltaY );
1081
+ CGPoint originalPoint ;
1082
+ originalPoint .x = event .data .mouse .x - deltaX ;
1083
+ originalPoint .y = event .data .mouse .y - deltaY ;
1084
+ CGWarpMouseCursorPosition (originalPoint );
1085
+ }
1075
1086
break ;
1076
1087
1077
-
1078
1088
case kCGEventScrollWheel :
1079
1089
process_mouse_wheel (timestamp , event_ref );
1080
1090
break ;
@@ -1126,6 +1136,14 @@ UIOHOOK_API void grab_mouse_click(bool enabled) {
1126
1136
}
1127
1137
}
1128
1138
1139
+ UIOHOOK_API void grab_mouse_move (bool enabled ) {
1140
+ grab_mouse_move_event = enabled ;
1141
+ CGDirectDisplayID displays [2 ];
1142
+ uint32_t dcnt ;
1143
+ CGGetActiveDisplayList (2 , displays , & dcnt );
1144
+ logger (LOG_LEVEL_DEBUG , "%s [%u]: get displays. (%d) (%d)\n" ,
1145
+ __FUNCTION__ , __LINE__ , dcnt , dcnt );
1146
+ }
1129
1147
UIOHOOK_API void grab_keyboard (bool enabled ){
1130
1148
grab_keyboard_event = enabled ;
1131
1149
}
0 commit comments