Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions extensions/eventtap/libeventtap_event.m
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,18 @@ static int eventtap_event_getButtonState(lua_State* L) {
return 1;
}

// Undocumented event fields
static const CGEventField kCGEventGestureHIDType = (CGEventField)110;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static const CGEventField kCGEventGesturePhase = (CGEventField)132;
static const CGEventField kCGEventGestureScrollY = (CGEventField)119;
static const CGEventField kCGEventGestureSwipeMotion = (CGEventField)123;
static const CGEventField kCGEventGestureSwipeProgress = (CGEventField)124;
static const CGEventField kCGEventGestureSwipeVelocityX = (CGEventField)129;
static const CGEventField kCGEventGestureSwipeVelocityY = (CGEventField)130;
static const CGEventField kCGEventGestureZoomDeltaX = (CGEventField)139;
static const CGEventField kCGEventScrollGestureFlagBits = (CGEventField)135;
static const CGEventField kCGSEventTypeField = (CGEventField)55;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this it's the same as setType


/// hs.eventtap.event:setProperty(prop, value)
/// Method
/// Sets a property of the event
Expand All @@ -809,15 +821,20 @@ static int eventtap_event_getButtonState(lua_State* L) {
static int eventtap_event_setProperty(lua_State* L) {
CGEventRef event = *(CGEventRef*)luaL_checkudata(L, 1, EVENT_USERDATA_TAG);
CGEventField field = (CGEventField)(luaL_checkinteger(L, 2));
if ((field == kCGMouseEventPressure) || // These fields use a double (floating point number)
if ((field == kCGEventGestureScrollY) || // These fields use a double (floating point number)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really a very small list of properties - with just these added, and still no way to explicitly specify that you want to set (or get) the property as a double, eventually someone will have to come back to this list and add more. Let's not throw out the code to dynamically detect whether you want to set the value as an integer or double. In fact that code is always correct, since CG seems to internally cast values from int to double and vice versa when you get or set them with the wrong function.

Copy link
Copy Markdown

@tbodt tbodt Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact that code is always correct, since CG seems to internally cast values from int to double and vice versa when you get or set them with the wrong function.

My bad - turns out when you get or set a float property using ints, it just gets or sets 0. I'm now convinced it's really best to add special getPropertyFloat and setPropertyFloat functions.

(Using floats to get or set an int property works fine, though.)

(field == kCGEventGestureSwipeProgress) ||
(field == kCGEventGestureSwipeVelocityX) ||
(field == kCGEventGestureSwipeVelocityY) ||
(field == kCGEventGestureZoomDeltaX) ||
(field == kCGMouseEventPressure) ||
(field == kCGScrollWheelEventFixedPtDeltaAxis1) ||
(field == kCGScrollWheelEventFixedPtDeltaAxis2) ||
(field == kCGScrollWheelEventFixedPtDeltaAxis3) ||
(field == kCGTabletEventPointPressure) ||
(field == kCGTabletEventTiltX) ||
(field == kCGTabletEventTiltY) ||
(field == kCGTabletEventRotation) ||
(field == kCGTabletEventTangentialPressure)) {
(field == kCGTabletEventTangentialPressure) ||
(field == kCGTabletEventTiltX) ||
(field == kCGTabletEventTiltY)) {
double value = luaL_checknumber(L, 3) ;
CGEventSetDoubleValueField(event, field, value);
} else {
Expand Down Expand Up @@ -1409,13 +1426,23 @@ static void pushtypestable(lua_State* L) {
/// * The constants defined in this table are as follows:
/// (I) in the description indicates that this property is returned or set as an integer
/// (N) in the description indicates that this property is returned or set as a number (floating point)
/// * eventGestureHIDType -- (I) The HID gesture type
/// * eventGesturePhase -- (I) Gesture phase bitfield
/// * eventGestureScrollY -- (N) Scroll gesture Y coordinate
/// * eventGestureSwipeMotion -- (I) Swipe gesture motion direction
/// * eventGestureSwipeProgress -- (N) Swipe gesture distance
/// * eventGestureSwipeVelocityX -- (N) Swipe gesture X velocity
/// * eventGestureSwipeVelocityY -- (N) Swipe gesture Y velocity
/// * eventGestureZoomDeltaX -- (N) Zoom gesture delta X
/// * eventScrollGestureFlagBits -- (I) Gesture flags
/// * eventSourceGroupID -- (I) The event source Unix effective GID.
/// * eventSourceStateID -- (I) The event source state ID used to create this event.
/// * eventSourceUnixProcessID -- (I) The event source Unix process ID.
/// * eventSourceUserData -- (I) Event source user-supplied data, up to 64 bits.
/// * eventSourceUserID -- (I) The event source Unix effective UID.
/// * eventTargetProcessSerialNumber -- (I) The event target process serial number. The value is a 64-bit long word.
/// * eventTargetUnixProcessID -- (I) The event target Unix process ID.
/// * eventTypeField -- (I) The event type
/// * eventUnacceleratedPointerMovementX -- Undocumented, assumed Integer
/// * eventUnacceleratedPointerMovementY -- Undocumented, assumed Integer
/// * keyboardEventAutorepeat -- (I) Non-zero when this is an autorepeat of a key-down, and zero otherwise.
Expand Down Expand Up @@ -1532,6 +1559,17 @@ static void pushpropertiestable(lua_State* L) {
lua_pushinteger(L, kCGMouseEventWindowUnderMousePointerThatCanHandleThisEvent) ; lua_setfield(L, -2, "mouseEventWindowUnderMousePointerThatCanHandleThisEvent") ;
lua_pushinteger(L, kCGEventUnacceleratedPointerMovementX) ; lua_setfield(L, -2, "eventUnacceleratedPointerMovementX") ;
lua_pushinteger(L, kCGEventUnacceleratedPointerMovementY) ; lua_setfield(L, -2, "eventUnacceleratedPointerMovementY") ;

lua_pushinteger(L, kCGEventGestureHIDType) ; lua_setfield(L, -2, "eventGestureHIDType") ;
lua_pushinteger(L, kCGEventGesturePhase) ; lua_setfield(L, -2, "eventGesturePhase") ;
lua_pushinteger(L, kCGEventGestureScrollY) ; lua_setfield(L, -2, "eventGestureScrollY") ;
lua_pushinteger(L, kCGEventGestureSwipeMotion) ; lua_setfield(L, -2, "eventGestureSwipeMotion") ;
lua_pushinteger(L, kCGEventGestureSwipeProgress) ; lua_setfield(L, -2, "eventGestureSwipeProgress") ;
lua_pushinteger(L, kCGEventGestureSwipeVelocityX) ; lua_setfield(L, -2, "eventGestureSwipeVelocityX") ;
lua_pushinteger(L, kCGEventGestureSwipeVelocityY) ; lua_setfield(L, -2, "eventGestureSwipeVelocityY") ;
lua_pushinteger(L, kCGEventGestureZoomDeltaX) ; lua_setfield(L, -2, "eventGestureZoomDeltaX") ;
lua_pushinteger(L, kCGEventScrollGestureFlagBits) ; lua_setfield(L, -2, "eventScrollGestureFlagBits") ;
lua_pushinteger(L, kCGSEventTypeField) ; lua_setfield(L, -2, "eventTypeField") ;
}

/// hs.eventtap.event.rawFlagMasks[]
Expand Down
Loading