mirror of
https://github.com/robotn/gohook.git
synced 2024-12-03 19:36:54 +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 (is_pressed) {
|
||||
mouse_type = kCGEventLeftMouseDown;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mouse_type = kCGEventLeftMouseUp;
|
||||
}
|
||||
mouse_button = kCGMouseButtonLeft;
|
||||
}
|
||||
else if (event->data.mouse.button == MOUSE_BUTTON2) {
|
||||
} else if (event->data.mouse.button == MOUSE_BUTTON2) {
|
||||
if (is_pressed) {
|
||||
mouse_type = kCGEventRightMouseDown;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mouse_type = kCGEventRightMouseUp;
|
||||
}
|
||||
mouse_button = kCGMouseButtonRight;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (is_pressed) {
|
||||
mouse_type = kCGEventOtherMouseDown;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mouse_type = kCGEventOtherMouseUp;
|
||||
}
|
||||
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) {
|
||||
// Scrolling data is line-based.
|
||||
scroll_unit = kCGScrollEventUnitLine;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Scrolling data is pixel-based.
|
||||
scroll_unit = kCGScrollEventUnitPixel;
|
||||
}
|
||||
@ -156,8 +150,7 @@ static inline void post_mouse_motion_event(iohook_event * const event) {
|
||||
),
|
||||
0
|
||||
);
|
||||
}
|
||||
else if (event->mask & MASK_BUTTON1) {
|
||||
} else if (event->mask & MASK_BUTTON1) {
|
||||
cg_event = CGEventCreateMouseEvent(src,
|
||||
kCGEventLeftMouseDragged,
|
||||
CGPointMake(
|
||||
@ -166,8 +159,7 @@ static inline void post_mouse_motion_event(iohook_event * const event) {
|
||||
),
|
||||
kCGMouseButtonLeft
|
||||
);
|
||||
}
|
||||
else if (event->mask & MASK_BUTTON2) {
|
||||
} else if (event->mask & MASK_BUTTON2) {
|
||||
cg_event = CGEventCreateMouseEvent(src,
|
||||
kCGEventRightMouseDragged,
|
||||
CGPointMake(
|
||||
@ -176,8 +168,7 @@ static inline void post_mouse_motion_event(iohook_event * const event) {
|
||||
),
|
||||
kCGMouseButtonRight
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cg_event = CGEventCreateMouseEvent(src,
|
||||
kCGEventOtherMouseDragged,
|
||||
CGPointMake(
|
||||
|
@ -491,98 +491,82 @@ static inline void process_modifier_changed(uint64_t timestamp, CGEventRef event
|
||||
// Process as a key pressed event.
|
||||
set_modifier_mask(MASK_SHIFT_L);
|
||||
process_key_pressed(timestamp, event_ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Process as a key released event.
|
||||
unset_modifier_mask(MASK_SHIFT_L);
|
||||
process_key_released(timestamp, event_ref);
|
||||
}
|
||||
}
|
||||
else if (keycode == kVK_Control) {
|
||||
} else if (keycode == kVK_Control) {
|
||||
if (event_mask & kCGEventFlagMaskControl) {
|
||||
// Process as a key pressed event.
|
||||
set_modifier_mask(MASK_CTRL_L);
|
||||
process_key_pressed(timestamp, event_ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Process as a key released event.
|
||||
unset_modifier_mask(MASK_CTRL_L);
|
||||
process_key_released(timestamp, event_ref);
|
||||
}
|
||||
}
|
||||
else if (keycode == kVK_Command) {
|
||||
} else if (keycode == kVK_Command) {
|
||||
if (event_mask & kCGEventFlagMaskCommand) {
|
||||
// Process as a key pressed event.
|
||||
set_modifier_mask(MASK_META_L);
|
||||
process_key_pressed(timestamp, event_ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Process as a key released event.
|
||||
unset_modifier_mask(MASK_META_L);
|
||||
process_key_released(timestamp, event_ref);
|
||||
}
|
||||
}
|
||||
else if (keycode == kVK_Option) {
|
||||
} else if (keycode == kVK_Option) {
|
||||
if (event_mask & kCGEventFlagMaskAlternate) {
|
||||
// Process as a key pressed event.
|
||||
set_modifier_mask(MASK_ALT_L);
|
||||
process_key_pressed(timestamp, event_ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Process as a key released event.
|
||||
unset_modifier_mask(MASK_ALT_L);
|
||||
process_key_released(timestamp, event_ref);
|
||||
}
|
||||
}
|
||||
else if (keycode == kVK_RightShift) {
|
||||
} else if (keycode == kVK_RightShift) {
|
||||
if (event_mask & kCGEventFlagMaskShift) {
|
||||
// Process as a key pressed event.
|
||||
set_modifier_mask(MASK_SHIFT_R);
|
||||
process_key_pressed(timestamp, event_ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Process as a key released event.
|
||||
unset_modifier_mask(MASK_SHIFT_R);
|
||||
process_key_released(timestamp, event_ref);
|
||||
}
|
||||
}
|
||||
else if (keycode == kVK_RightControl) {
|
||||
} else if (keycode == kVK_RightControl) {
|
||||
if (event_mask & kCGEventFlagMaskControl) {
|
||||
// Process as a key pressed event.
|
||||
set_modifier_mask(MASK_CTRL_R);
|
||||
process_key_pressed(timestamp, event_ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Process as a key released event.
|
||||
unset_modifier_mask(MASK_CTRL_R);
|
||||
process_key_released(timestamp, event_ref);
|
||||
}
|
||||
}
|
||||
else if (keycode == kVK_RightCommand) {
|
||||
} else if (keycode == kVK_RightCommand) {
|
||||
if (event_mask & kCGEventFlagMaskCommand) {
|
||||
// Process as a key pressed event.
|
||||
set_modifier_mask(MASK_META_R);
|
||||
process_key_pressed(timestamp, event_ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Process as a key released event.
|
||||
unset_modifier_mask(MASK_META_R);
|
||||
process_key_released(timestamp, event_ref);
|
||||
}
|
||||
}
|
||||
else if (keycode == kVK_RightOption) {
|
||||
} else if (keycode == kVK_RightOption) {
|
||||
if (event_mask & kCGEventFlagMaskAlternate) {
|
||||
// Process as a key pressed event.
|
||||
set_modifier_mask(MASK_ALT_R);
|
||||
process_key_pressed(timestamp, event_ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Process as a key released event.
|
||||
unset_modifier_mask(MASK_ALT_R);
|
||||
process_key_released(timestamp, event_ref);
|
||||
}
|
||||
}
|
||||
else if (keycode == kVK_CapsLock) {
|
||||
} else if (keycode == kVK_CapsLock) {
|
||||
if (current_modifiers & MASK_CAPS_LOCK) {
|
||||
// Process as a key pressed event.
|
||||
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) {
|
||||
process_key_pressed(timestamp, ns_event);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
process_key_released(timestamp, ns_event);
|
||||
}
|
||||
|
||||
CFRelease(ns_event);
|
||||
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.
|
||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
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) {
|
||||
process_key_pressed(timestamp, ns_event);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
process_key_released(timestamp, ns_event);
|
||||
}
|
||||
|
||||
CFRelease(ns_event);
|
||||
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.
|
||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
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) {
|
||||
process_key_pressed(timestamp, ns_event);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
process_key_released(timestamp, ns_event);
|
||||
}
|
||||
|
||||
CFRelease(ns_event);
|
||||
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.
|
||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
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) {
|
||||
process_key_pressed(timestamp, ns_event);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
process_key_released(timestamp, ns_event);
|
||||
}
|
||||
|
||||
CFRelease(ns_event);
|
||||
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.
|
||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
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) {
|
||||
process_key_pressed(timestamp, ns_event);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
process_key_released(timestamp, ns_event);
|
||||
}
|
||||
|
||||
CFRelease(ns_event);
|
||||
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.
|
||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
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) {
|
||||
process_key_pressed(timestamp, ns_event);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
process_key_released(timestamp, ns_event);
|
||||
}
|
||||
|
||||
CFRelease(ns_event);
|
||||
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.
|
||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
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) {
|
||||
process_key_pressed(timestamp, ns_event);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
process_key_released(timestamp, ns_event);
|
||||
}
|
||||
|
||||
CFRelease(ns_event);
|
||||
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.
|
||||
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
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) {
|
||||
process_key_pressed(timestamp, ns_event);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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 (click_count < USHRT_MAX) {
|
||||
click_count++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
logger(LOG_LEVEL_WARN, "%s [%u]: Click count overflow detected!\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Reset the click count.
|
||||
click_count = 1;
|
||||
|
||||
@ -871,8 +837,7 @@ static inline void process_mouse_moved(uint64_t timestamp, CGEventRef event_ref)
|
||||
|
||||
if (mouse_dragged) {
|
||||
event.type = EVENT_MOUSE_DRAGGED;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
event.type = EVENT_MOUSE_MOVED;
|
||||
}
|
||||
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) {
|
||||
// Scrolling data is line-based.
|
||||
event.data.wheel.type = WHEEL_BLOCK_SCROLL;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Scrolling data is pixel-based.
|
||||
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).
|
||||
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);
|
||||
|
||||
// Scrolling data uses a fixed-point 16.16 signed integer format (Ex: 1.0 = 0x00010000).
|
||||
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.
|
||||
event.data.wheel.amount = 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) {
|
||||
// Wheel Rotated Up or Down.
|
||||
event.data.wheel.direction = WHEEL_VERTICAL_DIRECTION;
|
||||
}
|
||||
else { // data->event.u.u.detail == WheelLeft || data->event.u.u.detail == WheelRight
|
||||
} else {
|
||||
// data->event.u.u.detail == WheelLeft || data->event.u.u.detail == WheelRight
|
||||
// Wheel Rotated Left or Right.
|
||||
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.
|
||||
if (button == 4) {
|
||||
set_modifier_mask(MOUSE_BUTTON4);
|
||||
}
|
||||
else if (button == 5) {
|
||||
} else if (button == 5) {
|
||||
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.
|
||||
if (button == 4) {
|
||||
unset_modifier_mask(MOUSE_BUTTON4);
|
||||
}
|
||||
else if (button == 5) {
|
||||
} else if (button == 5) {
|
||||
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!
|
||||
restart_tap = true;
|
||||
CFRunLoopStop(CFRunLoopGetCurrent());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// In theory this *should* never execute.
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: Unhandled Darwin event: %#X.\n",
|
||||
__FUNCTION__, __LINE__, (unsigned int) type);
|
||||
@ -1100,8 +1059,7 @@ CGEventRef hook_event_proc(CGEventTapProxy tap_proxy, CGEventType type, CGEventR
|
||||
CGEventRef result_ref = NULL;
|
||||
if (event.reserved ^ 0x01) {
|
||||
result_ref = event_ref;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: Consuming the current event. (%#X) (%#p)\n",
|
||||
__FUNCTION__, __LINE__, type, event_ref);
|
||||
}
|
||||
@ -1328,8 +1286,7 @@ IOHOOK_API int hook_run() {
|
||||
|
||||
// Free the hook structure.
|
||||
free(hook);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
status = IOHOOK_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
} while (restart_tap);
|
||||
|
Loading…
Reference in New Issue
Block a user