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
47 changes: 47 additions & 0 deletions extensions/eventtap/libeventtap_event.m
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,27 @@ static int eventtap_event_getProperty(lua_State* L) {
return 1;
}

/// hs.eventtap.event:getPropertyFloat(prop) -> number
/// Method
/// Gets a property of the event as a number
///
/// Parameters:
/// * prop - A value taken from `hs.eventtap.event.properties`
///
/// Returns:
/// * A number containing the value of the requested property
///
/// Notes:
/// * This method is for undocumented properties. `getProperty` will automatically behave like `getPropertyFloat` for properties documented as being floating point.
/// * The properties are `CGEventField` values, as documented at https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/index.html#//apple_ref/c/tdef/CGEventField
static int eventtap_event_getPropertyFloat(lua_State* L) {
CGEventRef event = *(CGEventRef*)luaL_checkudata(L, 1, EVENT_USERDATA_TAG);
CGEventField field = (CGEventField)(luaL_checkinteger(L, 2));

lua_pushnumber(L, CGEventGetDoubleValueField(event, field));
return 1;
}

/// hs.eventtap.event:getButtonState(button) -> bool
/// Method
/// Gets the state of a mouse button in the event
Expand Down Expand Up @@ -829,6 +850,30 @@ static int eventtap_event_setProperty(lua_State* L) {
return 1;
}

/// hs.eventtap.event:setPropertyFloat(prop, value)
/// Method
/// Sets a property of the event as a float
///
/// Parameters:
/// * prop - A value from `hs.eventtap.event.properties`
/// * value - A number containing the value of the specified property
///
/// Returns:
/// * The `hs.eventtap.event` object.
///
/// Notes:
/// * This method is for undocumented properties. `setProperty` will automatically behave like `setPropertyFloat` for properties documented as being floating point.
/// * The properties are `CGEventField` values, as documented at https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/index.html#//apple_ref/c/tdef/CGEventField
static int eventtap_event_setPropertyFloat(lua_State* L) {
CGEventRef event = *(CGEventRef*)luaL_checkudata(L, 1, EVENT_USERDATA_TAG);
CGEventField field = (CGEventField)(luaL_checkinteger(L, 2));
double value = luaL_checknumber(L, 3) ;
CGEventSetDoubleValueField(event, field, value);

lua_settop(L,1) ;
return 1;
}

/// hs.eventtap.event.newKeyEvent([mods], key, isdown) -> event
/// Constructor
/// Creates a keyboard event
Expand Down Expand Up @@ -1623,7 +1668,9 @@ static int meta_gc(lua_State* __unused L) {
{"getTouchDetails", eventtap_event_getTouchDetails},
{"post", eventtap_event_post},
{"getProperty", eventtap_event_getProperty},
{"getPropertyFloat",eventtap_event_getPropertyFloat},
{"setProperty", eventtap_event_setProperty},
{"setPropertyFloat",eventtap_event_setPropertyFloat},
{"getButtonState", eventtap_event_getButtonState},
{"getRawEventData", eventtap_event_getRawEventData},
{"getCharacters", eventtap_event_getCharacters},
Expand Down