mirror of
https://github.com/robotn/gohook.git
synced 2024-12-04 20:06:42 +08:00
update code style
This commit is contained in:
parent
d17136bdf9
commit
80d080b140
@ -77,26 +77,21 @@ static inline void post_mouse_button_event(iohook_event * const event, bool is_p
|
|||||||
if (event->data.mouse.button == MOUSE_BUTTON1) {
|
if (event->data.mouse.button == MOUSE_BUTTON1) {
|
||||||
if (is_pressed) {
|
if (is_pressed) {
|
||||||
mouse_type = kCGEventLeftMouseDown;
|
mouse_type = kCGEventLeftMouseDown;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
mouse_type = kCGEventLeftMouseUp;
|
mouse_type = kCGEventLeftMouseUp;
|
||||||
}
|
}
|
||||||
mouse_button = kCGMouseButtonLeft;
|
mouse_button = kCGMouseButtonLeft;
|
||||||
}
|
} else if (event->data.mouse.button == MOUSE_BUTTON2) {
|
||||||
else if (event->data.mouse.button == MOUSE_BUTTON2) {
|
|
||||||
if (is_pressed) {
|
if (is_pressed) {
|
||||||
mouse_type = kCGEventRightMouseDown;
|
mouse_type = kCGEventRightMouseDown;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
mouse_type = kCGEventRightMouseUp;
|
mouse_type = kCGEventRightMouseUp;
|
||||||
}
|
}
|
||||||
mouse_button = kCGMouseButtonRight;
|
mouse_button = kCGMouseButtonRight;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (is_pressed) {
|
if (is_pressed) {
|
||||||
mouse_type = kCGEventOtherMouseDown;
|
mouse_type = kCGEventOtherMouseDown;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
mouse_type = kCGEventOtherMouseUp;
|
mouse_type = kCGEventOtherMouseUp;
|
||||||
}
|
}
|
||||||
mouse_button = event->data.mouse.button - 1;
|
mouse_button = event->data.mouse.button - 1;
|
||||||
@ -125,8 +120,7 @@ static inline void post_mouse_wheel_event(iohook_event * const event) {
|
|||||||
if (event->data.wheel.type == WHEEL_BLOCK_SCROLL) {
|
if (event->data.wheel.type == WHEEL_BLOCK_SCROLL) {
|
||||||
// Scrolling data is line-based.
|
// Scrolling data is line-based.
|
||||||
scroll_unit = kCGScrollEventUnitLine;
|
scroll_unit = kCGScrollEventUnitLine;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Scrolling data is pixel-based.
|
// Scrolling data is pixel-based.
|
||||||
scroll_unit = kCGScrollEventUnitPixel;
|
scroll_unit = kCGScrollEventUnitPixel;
|
||||||
}
|
}
|
||||||
@ -156,8 +150,7 @@ static inline void post_mouse_motion_event(iohook_event * const event) {
|
|||||||
),
|
),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
} else if (event->mask & MASK_BUTTON1) {
|
||||||
else if (event->mask & MASK_BUTTON1) {
|
|
||||||
cg_event = CGEventCreateMouseEvent(src,
|
cg_event = CGEventCreateMouseEvent(src,
|
||||||
kCGEventLeftMouseDragged,
|
kCGEventLeftMouseDragged,
|
||||||
CGPointMake(
|
CGPointMake(
|
||||||
@ -166,8 +159,7 @@ static inline void post_mouse_motion_event(iohook_event * const event) {
|
|||||||
),
|
),
|
||||||
kCGMouseButtonLeft
|
kCGMouseButtonLeft
|
||||||
);
|
);
|
||||||
}
|
} else if (event->mask & MASK_BUTTON2) {
|
||||||
else if (event->mask & MASK_BUTTON2) {
|
|
||||||
cg_event = CGEventCreateMouseEvent(src,
|
cg_event = CGEventCreateMouseEvent(src,
|
||||||
kCGEventRightMouseDragged,
|
kCGEventRightMouseDragged,
|
||||||
CGPointMake(
|
CGPointMake(
|
||||||
@ -176,8 +168,7 @@ static inline void post_mouse_motion_event(iohook_event * const event) {
|
|||||||
),
|
),
|
||||||
kCGMouseButtonRight
|
kCGMouseButtonRight
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
cg_event = CGEventCreateMouseEvent(src,
|
cg_event = CGEventCreateMouseEvent(src,
|
||||||
kCGEventOtherMouseDragged,
|
kCGEventOtherMouseDragged,
|
||||||
CGPointMake(
|
CGPointMake(
|
||||||
|
@ -491,98 +491,82 @@ static inline void process_modifier_changed(uint64_t timestamp, CGEventRef event
|
|||||||
// Process as a key pressed event.
|
// Process as a key pressed event.
|
||||||
set_modifier_mask(MASK_SHIFT_L);
|
set_modifier_mask(MASK_SHIFT_L);
|
||||||
process_key_pressed(timestamp, event_ref);
|
process_key_pressed(timestamp, event_ref);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Process as a key released event.
|
// Process as a key released event.
|
||||||
unset_modifier_mask(MASK_SHIFT_L);
|
unset_modifier_mask(MASK_SHIFT_L);
|
||||||
process_key_released(timestamp, event_ref);
|
process_key_released(timestamp, event_ref);
|
||||||
}
|
}
|
||||||
}
|
} else if (keycode == kVK_Control) {
|
||||||
else if (keycode == kVK_Control) {
|
|
||||||
if (event_mask & kCGEventFlagMaskControl) {
|
if (event_mask & kCGEventFlagMaskControl) {
|
||||||
// Process as a key pressed event.
|
// Process as a key pressed event.
|
||||||
set_modifier_mask(MASK_CTRL_L);
|
set_modifier_mask(MASK_CTRL_L);
|
||||||
process_key_pressed(timestamp, event_ref);
|
process_key_pressed(timestamp, event_ref);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Process as a key released event.
|
// Process as a key released event.
|
||||||
unset_modifier_mask(MASK_CTRL_L);
|
unset_modifier_mask(MASK_CTRL_L);
|
||||||
process_key_released(timestamp, event_ref);
|
process_key_released(timestamp, event_ref);
|
||||||
}
|
}
|
||||||
}
|
} else if (keycode == kVK_Command) {
|
||||||
else if (keycode == kVK_Command) {
|
|
||||||
if (event_mask & kCGEventFlagMaskCommand) {
|
if (event_mask & kCGEventFlagMaskCommand) {
|
||||||
// Process as a key pressed event.
|
// Process as a key pressed event.
|
||||||
set_modifier_mask(MASK_META_L);
|
set_modifier_mask(MASK_META_L);
|
||||||
process_key_pressed(timestamp, event_ref);
|
process_key_pressed(timestamp, event_ref);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Process as a key released event.
|
// Process as a key released event.
|
||||||
unset_modifier_mask(MASK_META_L);
|
unset_modifier_mask(MASK_META_L);
|
||||||
process_key_released(timestamp, event_ref);
|
process_key_released(timestamp, event_ref);
|
||||||
}
|
}
|
||||||
}
|
} else if (keycode == kVK_Option) {
|
||||||
else if (keycode == kVK_Option) {
|
|
||||||
if (event_mask & kCGEventFlagMaskAlternate) {
|
if (event_mask & kCGEventFlagMaskAlternate) {
|
||||||
// Process as a key pressed event.
|
// Process as a key pressed event.
|
||||||
set_modifier_mask(MASK_ALT_L);
|
set_modifier_mask(MASK_ALT_L);
|
||||||
process_key_pressed(timestamp, event_ref);
|
process_key_pressed(timestamp, event_ref);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Process as a key released event.
|
// Process as a key released event.
|
||||||
unset_modifier_mask(MASK_ALT_L);
|
unset_modifier_mask(MASK_ALT_L);
|
||||||
process_key_released(timestamp, event_ref);
|
process_key_released(timestamp, event_ref);
|
||||||
}
|
}
|
||||||
}
|
} else if (keycode == kVK_RightShift) {
|
||||||
else if (keycode == kVK_RightShift) {
|
|
||||||
if (event_mask & kCGEventFlagMaskShift) {
|
if (event_mask & kCGEventFlagMaskShift) {
|
||||||
// Process as a key pressed event.
|
// Process as a key pressed event.
|
||||||
set_modifier_mask(MASK_SHIFT_R);
|
set_modifier_mask(MASK_SHIFT_R);
|
||||||
process_key_pressed(timestamp, event_ref);
|
process_key_pressed(timestamp, event_ref);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Process as a key released event.
|
// Process as a key released event.
|
||||||
unset_modifier_mask(MASK_SHIFT_R);
|
unset_modifier_mask(MASK_SHIFT_R);
|
||||||
process_key_released(timestamp, event_ref);
|
process_key_released(timestamp, event_ref);
|
||||||
}
|
}
|
||||||
}
|
} else if (keycode == kVK_RightControl) {
|
||||||
else if (keycode == kVK_RightControl) {
|
|
||||||
if (event_mask & kCGEventFlagMaskControl) {
|
if (event_mask & kCGEventFlagMaskControl) {
|
||||||
// Process as a key pressed event.
|
// Process as a key pressed event.
|
||||||
set_modifier_mask(MASK_CTRL_R);
|
set_modifier_mask(MASK_CTRL_R);
|
||||||
process_key_pressed(timestamp, event_ref);
|
process_key_pressed(timestamp, event_ref);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Process as a key released event.
|
// Process as a key released event.
|
||||||
unset_modifier_mask(MASK_CTRL_R);
|
unset_modifier_mask(MASK_CTRL_R);
|
||||||
process_key_released(timestamp, event_ref);
|
process_key_released(timestamp, event_ref);
|
||||||
}
|
}
|
||||||
}
|
} else if (keycode == kVK_RightCommand) {
|
||||||
else if (keycode == kVK_RightCommand) {
|
|
||||||
if (event_mask & kCGEventFlagMaskCommand) {
|
if (event_mask & kCGEventFlagMaskCommand) {
|
||||||
// Process as a key pressed event.
|
// Process as a key pressed event.
|
||||||
set_modifier_mask(MASK_META_R);
|
set_modifier_mask(MASK_META_R);
|
||||||
process_key_pressed(timestamp, event_ref);
|
process_key_pressed(timestamp, event_ref);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Process as a key released event.
|
// Process as a key released event.
|
||||||
unset_modifier_mask(MASK_META_R);
|
unset_modifier_mask(MASK_META_R);
|
||||||
process_key_released(timestamp, event_ref);
|
process_key_released(timestamp, event_ref);
|
||||||
}
|
}
|
||||||
}
|
} else if (keycode == kVK_RightOption) {
|
||||||
else if (keycode == kVK_RightOption) {
|
|
||||||
if (event_mask & kCGEventFlagMaskAlternate) {
|
if (event_mask & kCGEventFlagMaskAlternate) {
|
||||||
// Process as a key pressed event.
|
// Process as a key pressed event.
|
||||||
set_modifier_mask(MASK_ALT_R);
|
set_modifier_mask(MASK_ALT_R);
|
||||||
process_key_pressed(timestamp, event_ref);
|
process_key_pressed(timestamp, event_ref);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Process as a key released event.
|
// Process as a key released event.
|
||||||
unset_modifier_mask(MASK_ALT_R);
|
unset_modifier_mask(MASK_ALT_R);
|
||||||
process_key_released(timestamp, event_ref);
|
process_key_released(timestamp, event_ref);
|
||||||
}
|
}
|
||||||
}
|
} else if (keycode == kVK_CapsLock) {
|
||||||
else if (keycode == kVK_CapsLock) {
|
|
||||||
if (current_modifiers & MASK_CAPS_LOCK) {
|
if (current_modifiers & MASK_CAPS_LOCK) {
|
||||||
// Process as a key pressed event.
|
// Process as a key pressed event.
|
||||||
unset_modifier_mask(MASK_CAPS_LOCK);
|
unset_modifier_mask(MASK_CAPS_LOCK);
|
||||||
@ -631,15 +615,13 @@ static inline void process_system_key(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
|
|
||||||
if (key_down) {
|
if (key_down) {
|
||||||
process_key_pressed(timestamp, ns_event);
|
process_key_pressed(timestamp, ns_event);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
process_key_released(timestamp, ns_event);
|
process_key_released(timestamp, ns_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(ns_event);
|
CFRelease(ns_event);
|
||||||
CFRelease(src);
|
CFRelease(src);
|
||||||
}
|
} else if (key_code == NX_KEYTYPE_SOUND_UP) {
|
||||||
else if (key_code == NX_KEYTYPE_SOUND_UP) {
|
|
||||||
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
||||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_VolumeUp, key_down);
|
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_VolumeUp, key_down);
|
||||||
@ -647,15 +629,13 @@ static inline void process_system_key(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
|
|
||||||
if (key_down) {
|
if (key_down) {
|
||||||
process_key_pressed(timestamp, ns_event);
|
process_key_pressed(timestamp, ns_event);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
process_key_released(timestamp, ns_event);
|
process_key_released(timestamp, ns_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(ns_event);
|
CFRelease(ns_event);
|
||||||
CFRelease(src);
|
CFRelease(src);
|
||||||
}
|
} else if (key_code == NX_KEYTYPE_SOUND_DOWN) {
|
||||||
else if (key_code == NX_KEYTYPE_SOUND_DOWN) {
|
|
||||||
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
||||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_VolumeDown, key_down);
|
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_VolumeDown, key_down);
|
||||||
@ -663,15 +643,13 @@ static inline void process_system_key(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
|
|
||||||
if (key_down) {
|
if (key_down) {
|
||||||
process_key_pressed(timestamp, ns_event);
|
process_key_pressed(timestamp, ns_event);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
process_key_released(timestamp, ns_event);
|
process_key_released(timestamp, ns_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(ns_event);
|
CFRelease(ns_event);
|
||||||
CFRelease(src);
|
CFRelease(src);
|
||||||
}
|
} else if (key_code == NX_KEYTYPE_MUTE) {
|
||||||
else if (key_code == NX_KEYTYPE_MUTE) {
|
|
||||||
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
||||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_Mute, key_down);
|
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_Mute, key_down);
|
||||||
@ -679,16 +657,13 @@ static inline void process_system_key(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
|
|
||||||
if (key_down) {
|
if (key_down) {
|
||||||
process_key_pressed(timestamp, ns_event);
|
process_key_pressed(timestamp, ns_event);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
process_key_released(timestamp, ns_event);
|
process_key_released(timestamp, ns_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(ns_event);
|
CFRelease(ns_event);
|
||||||
CFRelease(src);
|
CFRelease(src);
|
||||||
}
|
} else if (key_code == NX_KEYTYPE_EJECT) {
|
||||||
|
|
||||||
else if (key_code == NX_KEYTYPE_EJECT) {
|
|
||||||
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
||||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_NX_Eject, key_down);
|
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_NX_Eject, key_down);
|
||||||
@ -696,15 +671,13 @@ static inline void process_system_key(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
|
|
||||||
if (key_down) {
|
if (key_down) {
|
||||||
process_key_pressed(timestamp, ns_event);
|
process_key_pressed(timestamp, ns_event);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
process_key_released(timestamp, ns_event);
|
process_key_released(timestamp, ns_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(ns_event);
|
CFRelease(ns_event);
|
||||||
CFRelease(src);
|
CFRelease(src);
|
||||||
}
|
} else if (key_code == NX_KEYTYPE_PLAY) {
|
||||||
else if (key_code == NX_KEYTYPE_PLAY) {
|
|
||||||
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
||||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_MEDIA_Play, key_down);
|
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_MEDIA_Play, key_down);
|
||||||
@ -712,15 +685,13 @@ static inline void process_system_key(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
|
|
||||||
if (key_down) {
|
if (key_down) {
|
||||||
process_key_pressed(timestamp, ns_event);
|
process_key_pressed(timestamp, ns_event);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
process_key_released(timestamp, ns_event);
|
process_key_released(timestamp, ns_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(ns_event);
|
CFRelease(ns_event);
|
||||||
CFRelease(src);
|
CFRelease(src);
|
||||||
}
|
} else if (key_code == NX_KEYTYPE_FAST) {
|
||||||
else if (key_code == NX_KEYTYPE_FAST) {
|
|
||||||
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
||||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_MEDIA_Next, key_down);
|
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_MEDIA_Next, key_down);
|
||||||
@ -728,15 +699,13 @@ static inline void process_system_key(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
|
|
||||||
if (key_down) {
|
if (key_down) {
|
||||||
process_key_pressed(timestamp, ns_event);
|
process_key_pressed(timestamp, ns_event);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
process_key_released(timestamp, ns_event);
|
process_key_released(timestamp, ns_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(ns_event);
|
CFRelease(ns_event);
|
||||||
CFRelease(src);
|
CFRelease(src);
|
||||||
}
|
} else if (key_code == NX_KEYTYPE_REWIND) {
|
||||||
else if (key_code == NX_KEYTYPE_REWIND) {
|
|
||||||
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
// It doesn't appear like we can modify the event coming in, so we will fabricate a new event.
|
||||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_MEDIA_Previous, key_down);
|
CGEventRef ns_event = CGEventCreateKeyboardEvent(src, kVK_MEDIA_Previous, key_down);
|
||||||
@ -744,8 +713,7 @@ static inline void process_system_key(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
|
|
||||||
if (key_down) {
|
if (key_down) {
|
||||||
process_key_pressed(timestamp, ns_event);
|
process_key_pressed(timestamp, ns_event);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
process_key_released(timestamp, ns_event);
|
process_key_released(timestamp, ns_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -767,13 +735,11 @@ static inline void process_button_pressed(uint64_t timestamp, CGEventRef event_r
|
|||||||
if (button == click_button && (long int) (timestamp - click_time) <= hook_get_multi_click_time()) {
|
if (button == click_button && (long int) (timestamp - click_time) <= hook_get_multi_click_time()) {
|
||||||
if (click_count < USHRT_MAX) {
|
if (click_count < USHRT_MAX) {
|
||||||
click_count++;
|
click_count++;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
logger(LOG_LEVEL_WARN, "%s [%u]: Click count overflow detected!\n",
|
logger(LOG_LEVEL_WARN, "%s [%u]: Click count overflow detected!\n",
|
||||||
__FUNCTION__, __LINE__);
|
__FUNCTION__, __LINE__);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Reset the click count.
|
// Reset the click count.
|
||||||
click_count = 1;
|
click_count = 1;
|
||||||
|
|
||||||
@ -871,8 +837,7 @@ static inline void process_mouse_moved(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
|
|
||||||
if (mouse_dragged) {
|
if (mouse_dragged) {
|
||||||
event.type = EVENT_MOUSE_DRAGGED;
|
event.type = EVENT_MOUSE_DRAGGED;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
event.type = EVENT_MOUSE_MOVED;
|
event.type = EVENT_MOUSE_MOVED;
|
||||||
}
|
}
|
||||||
event.mask = get_modifiers();
|
event.mask = get_modifiers();
|
||||||
@ -917,8 +882,7 @@ static inline void process_mouse_wheel(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
if (CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventIsContinuous) == 0) {
|
if (CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventIsContinuous) == 0) {
|
||||||
// Scrolling data is line-based.
|
// Scrolling data is line-based.
|
||||||
event.data.wheel.type = WHEEL_BLOCK_SCROLL;
|
event.data.wheel.type = WHEEL_BLOCK_SCROLL;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Scrolling data is pixel-based.
|
// Scrolling data is pixel-based.
|
||||||
event.data.wheel.type = WHEEL_UNIT_SCROLL;
|
event.data.wheel.type = WHEEL_UNIT_SCROLL;
|
||||||
}
|
}
|
||||||
@ -934,14 +898,12 @@ static inline void process_mouse_wheel(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
// Scrolling data uses a fixed-point 16.16 signed integer format (Ex: 1.0 = 0x00010000).
|
// Scrolling data uses a fixed-point 16.16 signed integer format (Ex: 1.0 = 0x00010000).
|
||||||
event.data.wheel.rotation = CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis1) * -1;
|
event.data.wheel.rotation = CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis1) * -1;
|
||||||
|
|
||||||
}
|
} else if(CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis2) != 0) {
|
||||||
else if(CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis2) != 0) {
|
|
||||||
event.data.wheel.amount = CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventPointDeltaAxis2) / CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis2);
|
event.data.wheel.amount = CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventPointDeltaAxis2) / CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis2);
|
||||||
|
|
||||||
// Scrolling data uses a fixed-point 16.16 signed integer format (Ex: 1.0 = 0x00010000).
|
// Scrolling data uses a fixed-point 16.16 signed integer format (Ex: 1.0 = 0x00010000).
|
||||||
event.data.wheel.rotation = CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis2) * -1;
|
event.data.wheel.rotation = CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis2) * -1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
//Fail Silently if a 3rd axis gets added without changing this section of code.
|
//Fail Silently if a 3rd axis gets added without changing this section of code.
|
||||||
event.data.wheel.amount = 0;
|
event.data.wheel.amount = 0;
|
||||||
event.data.wheel.rotation = 0;
|
event.data.wheel.rotation = 0;
|
||||||
@ -952,8 +914,8 @@ static inline void process_mouse_wheel(uint64_t timestamp, CGEventRef event_ref)
|
|||||||
if (CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis1) != 0) {
|
if (CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis1) != 0) {
|
||||||
// Wheel Rotated Up or Down.
|
// Wheel Rotated Up or Down.
|
||||||
event.data.wheel.direction = WHEEL_VERTICAL_DIRECTION;
|
event.data.wheel.direction = WHEEL_VERTICAL_DIRECTION;
|
||||||
}
|
} else {
|
||||||
else { // data->event.u.u.detail == WheelLeft || data->event.u.u.detail == WheelRight
|
// data->event.u.u.detail == WheelLeft || data->event.u.u.detail == WheelRight
|
||||||
// Wheel Rotated Left or Right.
|
// Wheel Rotated Left or Right.
|
||||||
event.data.wheel.direction = WHEEL_HORIZONTAL_DIRECTION;
|
event.data.wheel.direction = WHEEL_HORIZONTAL_DIRECTION;
|
||||||
}
|
}
|
||||||
@ -1013,8 +975,7 @@ CGEventRef hook_event_proc(CGEventTapProxy tap_proxy, CGEventType type, CGEventR
|
|||||||
// Add support for mouse 4 & 5.
|
// Add support for mouse 4 & 5.
|
||||||
if (button == 4) {
|
if (button == 4) {
|
||||||
set_modifier_mask(MOUSE_BUTTON4);
|
set_modifier_mask(MOUSE_BUTTON4);
|
||||||
}
|
} else if (button == 5) {
|
||||||
else if (button == 5) {
|
|
||||||
set_modifier_mask(MOUSE_BUTTON5);
|
set_modifier_mask(MOUSE_BUTTON5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1040,8 +1001,7 @@ CGEventRef hook_event_proc(CGEventTapProxy tap_proxy, CGEventType type, CGEventR
|
|||||||
// Add support for mouse 4 & 5.
|
// Add support for mouse 4 & 5.
|
||||||
if (button == 4) {
|
if (button == 4) {
|
||||||
unset_modifier_mask(MOUSE_BUTTON4);
|
unset_modifier_mask(MOUSE_BUTTON4);
|
||||||
}
|
} else if (button == 5) {
|
||||||
else if (button == 5) {
|
|
||||||
unset_modifier_mask(MOUSE_BUTTON5);
|
unset_modifier_mask(MOUSE_BUTTON5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1088,8 +1048,7 @@ CGEventRef hook_event_proc(CGEventTapProxy tap_proxy, CGEventType type, CGEventR
|
|||||||
// We need to restart the tap!
|
// We need to restart the tap!
|
||||||
restart_tap = true;
|
restart_tap = true;
|
||||||
CFRunLoopStop(CFRunLoopGetCurrent());
|
CFRunLoopStop(CFRunLoopGetCurrent());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// In theory this *should* never execute.
|
// In theory this *should* never execute.
|
||||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: Unhandled Darwin event: %#X.\n",
|
logger(LOG_LEVEL_DEBUG, "%s [%u]: Unhandled Darwin event: %#X.\n",
|
||||||
__FUNCTION__, __LINE__, (unsigned int) type);
|
__FUNCTION__, __LINE__, (unsigned int) type);
|
||||||
@ -1100,8 +1059,7 @@ CGEventRef hook_event_proc(CGEventTapProxy tap_proxy, CGEventType type, CGEventR
|
|||||||
CGEventRef result_ref = NULL;
|
CGEventRef result_ref = NULL;
|
||||||
if (event.reserved ^ 0x01) {
|
if (event.reserved ^ 0x01) {
|
||||||
result_ref = event_ref;
|
result_ref = event_ref;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: Consuming the current event. (%#X) (%#p)\n",
|
logger(LOG_LEVEL_DEBUG, "%s [%u]: Consuming the current event. (%#X) (%#p)\n",
|
||||||
__FUNCTION__, __LINE__, type, event_ref);
|
__FUNCTION__, __LINE__, type, event_ref);
|
||||||
}
|
}
|
||||||
@ -1328,8 +1286,7 @@ IOHOOK_API int hook_run() {
|
|||||||
|
|
||||||
// Free the hook structure.
|
// Free the hook structure.
|
||||||
free(hook);
|
free(hook);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
status = IOHOOK_ERROR_OUT_OF_MEMORY;
|
status = IOHOOK_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
} while (restart_tap);
|
} while (restart_tap);
|
||||||
|
Loading…
Reference in New Issue
Block a user