@@ -44,24 +44,6 @@ UIOHOOK_API void hook_set_dispatch_proc(dispatcher_t dispatch_proc, void *user_d
4444 dispatch_data = user_data ;
4545}
4646
47- #ifdef USE_EPOCH_TIME
48- static uint64_t get_unix_timestamp () {
49- FILETIME system_time ;
50-
51- // Get the local system time in UTC.
52- GetSystemTimeAsFileTime (& system_time );
53-
54- // Convert the local system time to a Unix epoch in MS.
55- // milliseconds = 100-nanoseconds / 10000
56- uint64_t timestamp = (((uint64_t ) system_time .dwHighDateTime << 32 ) | system_time .dwLowDateTime ) / 10000 ;
57-
58- // Convert Windows epoch to Unix epoch. (1970 - 1601 in milliseconds)
59- timestamp -= 11644473600000 ;
60-
61- return timestamp ;
62- }
63- #endif
64-
6547// Send out an event if a dispatcher was set.
6648static void dispatch_event (uiohook_event * const event ) {
6749 if (dispatch != NULL ) {
@@ -75,8 +57,9 @@ static void dispatch_event(uiohook_event *const event) {
7557 }
7658}
7759
78- bool dispatch_hook_enable () {
60+ bool dispatch_hook_enable (uint64_t timestamp ) {
7961 bool consumed = false;
62+
8063 // Initialize native input helper functions.
8164 load_input_helper ();
8265
@@ -99,14 +82,8 @@ bool dispatch_hook_enable() {
9982 return consumed ;
10083}
10184
102- bool dispatch_hook_disable () {
85+ bool dispatch_hook_disable (uint64_t timestamp ) {
10386 bool consumed = false;
104- // Get the local system time in UNIX epoch form.
105- #ifdef USE_EPOCH_TIME
106- uint64_t timestamp = get_unix_timestamp ();
107- #else
108- uint64_t timestamp = GetMessageTime ();
109- #endif
11087
11188 // Populate the hook stop event.
11289 uio_event .time = timestamp ;
@@ -123,13 +100,8 @@ bool dispatch_hook_disable() {
123100 return consumed ;
124101}
125102
126- bool dispatch_key_press (KBDLLHOOKSTRUCT * kbhook ) {
103+ bool dispatch_key_press (uint64_t timestamp , KBDLLHOOKSTRUCT * kbhook ) {
127104 bool consumed = false;
128- #ifdef USE_EPOCH_TIME
129- uint64_t timestamp = get_unix_timestamp ();
130- #else
131- uint64_t timestamp = kbhook -> time ;
132- #endif
133105
134106 // Check and setup modifiers.
135107 if (kbhook -> vkCode == VK_LSHIFT ) { set_modifier_mask (MASK_SHIFT_L ); }
@@ -197,13 +169,8 @@ bool dispatch_key_press(KBDLLHOOKSTRUCT *kbhook) {
197169 return consumed ;
198170}
199171
200- bool dispatch_key_release (KBDLLHOOKSTRUCT * kbhook ) {
172+ bool dispatch_key_release (uint64_t timestamp , KBDLLHOOKSTRUCT * kbhook ) {
201173 bool consumed = false;
202- #ifdef USE_EPOCH_TIME
203- uint64_t timestamp = get_unix_timestamp ();
204- #else
205- uint64_t timestamp = kbhook -> time ;
206- #endif
207174
208175 // Check and setup modifiers.
209176 if (kbhook -> vkCode == VK_LSHIFT ) { unset_modifier_mask (MASK_SHIFT_L ); }
@@ -241,13 +208,8 @@ bool dispatch_key_release(KBDLLHOOKSTRUCT *kbhook) {
241208 return consumed ;
242209}
243210
244- bool dispatch_button_press (MSLLHOOKSTRUCT * mshook , uint16_t button ) {
211+ bool dispatch_button_press (uint64_t timestamp , MSLLHOOKSTRUCT * mshook , uint16_t button ) {
245212 bool consumed = false;
246- #ifdef USE_EPOCH_TIME
247- uint64_t timestamp = get_unix_timestamp ();
248- #else
249- uint64_t timestamp = mshook -> time ;
250- #endif
251213
252214 // Track the number of clicks, the button must match the previous button.
253215 if (button == click_button && (long int ) (timestamp - click_time ) <= hook_get_multi_click_time ()) {
@@ -298,13 +260,8 @@ bool dispatch_button_press(MSLLHOOKSTRUCT *mshook, uint16_t button) {
298260 return consumed ;
299261}
300262
301- bool dispatch_button_release (MSLLHOOKSTRUCT * mshook , uint16_t button ) {
263+ bool dispatch_button_release (uint64_t timestamp , MSLLHOOKSTRUCT * mshook , uint16_t button ) {
302264 bool consumed = false;
303- #ifdef USE_EPOCH_TIME
304- uint64_t timestamp = get_unix_timestamp ();
305- #else
306- uint64_t timestamp = mshook -> time ;
307- #endif
308265
309266 // Populate mouse released event.
310267 uio_event .time = timestamp ;
@@ -364,13 +321,8 @@ bool dispatch_button_release(MSLLHOOKSTRUCT *mshook, uint16_t button) {
364321}
365322
366323
367- bool dispatch_mouse_move (MSLLHOOKSTRUCT * mshook ) {
324+ bool dispatch_mouse_move (uint64_t timestamp , MSLLHOOKSTRUCT * mshook ) {
368325 bool consumed = false;
369- #ifdef USE_EPOCH_TIME
370- uint64_t timestamp = get_unix_timestamp ();
371- #else
372- uint64_t timestamp = mshook -> time ;
373- #endif
374326
375327 // We received a mouse move event with the mouse actually moving.
376328 // This verifies that the mouse was moved after being depressed.
@@ -415,13 +367,8 @@ bool dispatch_mouse_move(MSLLHOOKSTRUCT *mshook) {
415367 return consumed ;
416368}
417369
418- bool dispatch_mouse_wheel (MSLLHOOKSTRUCT * mshook , uint8_t direction ) {
370+ bool dispatch_mouse_wheel (uint64_t timestamp , MSLLHOOKSTRUCT * mshook , uint8_t direction ) {
419371 bool consumed = false;
420- #ifdef USE_EPOCH_TIME
421- uint64_t timestamp = get_unix_timestamp ();
422- #else
423- uint64_t timestamp = mshook -> time ;
424- #endif
425372
426373 // Track the number of clicks.
427374 // Reset the click count and previous button.
0 commit comments