@@ -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,17 +57,11 @@ 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;
80- // Initialize native input helper functions.
81- load_input_helper ();
8262
83- // Get the local system time in UNIX epoch form.
84- #ifdef USE_EPOCH_TIME
85- uint64_t timestamp = get_unix_timestamp ();
86- #else
87- uint64_t timestamp = GetMessageTime ();
88- #endif
63+ // Initialize native input helper.
64+ load_input_helper ();
8965
9066 // Populate the hook start event.
9167 uio_event .time = timestamp ;
@@ -99,14 +75,8 @@ bool dispatch_hook_enable() {
9975 return consumed ;
10076}
10177
102- bool dispatch_hook_disable () {
78+ bool dispatch_hook_disable (uint64_t timestamp ) {
10379 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
11080
11181 // Populate the hook stop event.
11282 uio_event .time = timestamp ;
@@ -117,19 +87,14 @@ bool dispatch_hook_disable() {
11787 dispatch_event (& uio_event );
11888 consumed = uio_event .mask & MASK_CONSUME ;
11989
120- // Deinitialize native input helper functions .
90+ // Uninitialize the native input helper.
12191 unload_input_helper ();
12292
12393 return consumed ;
12494}
12595
126- bool dispatch_key_press (KBDLLHOOKSTRUCT * kbhook ) {
96+ bool dispatch_key_press (uint64_t timestamp , KBDLLHOOKSTRUCT * kbhook ) {
12797 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
13398
13499 // Check and setup modifiers.
135100 if (kbhook -> vkCode == VK_LSHIFT ) { set_modifier_mask (MASK_SHIFT_L ); }
@@ -197,13 +162,8 @@ bool dispatch_key_press(KBDLLHOOKSTRUCT *kbhook) {
197162 return consumed ;
198163}
199164
200- bool dispatch_key_release (KBDLLHOOKSTRUCT * kbhook ) {
165+ bool dispatch_key_release (uint64_t timestamp , KBDLLHOOKSTRUCT * kbhook ) {
201166 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
207167
208168 // Check and setup modifiers.
209169 if (kbhook -> vkCode == VK_LSHIFT ) { unset_modifier_mask (MASK_SHIFT_L ); }
@@ -241,13 +201,8 @@ bool dispatch_key_release(KBDLLHOOKSTRUCT *kbhook) {
241201 return consumed ;
242202}
243203
244- bool dispatch_button_press (MSLLHOOKSTRUCT * mshook , uint16_t button ) {
204+ bool dispatch_button_press (uint64_t timestamp , MSLLHOOKSTRUCT * mshook , uint16_t button ) {
245205 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
251206
252207 // Track the number of clicks, the button must match the previous button.
253208 if (button == click_button && (long int ) (timestamp - click_time ) <= hook_get_multi_click_time ()) {
@@ -298,13 +253,8 @@ bool dispatch_button_press(MSLLHOOKSTRUCT *mshook, uint16_t button) {
298253 return consumed ;
299254}
300255
301- bool dispatch_button_release (MSLLHOOKSTRUCT * mshook , uint16_t button ) {
256+ bool dispatch_button_release (uint64_t timestamp , MSLLHOOKSTRUCT * mshook , uint16_t button ) {
302257 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
308258
309259 // Populate mouse released event.
310260 uio_event .time = timestamp ;
@@ -364,13 +314,8 @@ bool dispatch_button_release(MSLLHOOKSTRUCT *mshook, uint16_t button) {
364314}
365315
366316
367- bool dispatch_mouse_move (MSLLHOOKSTRUCT * mshook ) {
317+ bool dispatch_mouse_move (uint64_t timestamp , MSLLHOOKSTRUCT * mshook ) {
368318 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
374319
375320 // We received a mouse move event with the mouse actually moving.
376321 // This verifies that the mouse was moved after being depressed.
@@ -415,13 +360,8 @@ bool dispatch_mouse_move(MSLLHOOKSTRUCT *mshook) {
415360 return consumed ;
416361}
417362
418- bool dispatch_mouse_wheel (MSLLHOOKSTRUCT * mshook , uint8_t direction ) {
363+ bool dispatch_mouse_wheel (uint64_t timestamp , MSLLHOOKSTRUCT * mshook , uint8_t direction ) {
419364 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
425365
426366 // Track the number of clicks.
427367 // Reset the click count and previous button.
0 commit comments