hs.eventtap
hs.eventtap.event.newGesture
uses an external library by Calf Trail Software, LLC.hs.eventtap.event.properties -> table
hs.eventtap.event:getProperty()
and hs.eventtap.event:setProperty()
. The table supports forward (label to number) and reverse (number to label) lookups to increase its flexibility.hs.eventtap.event.rawFlagMasks[]
hs.eventtap.event.types -> table
hs.eventtap.new(...)
and returned by hs.eventtap.event:type()
. The table supports forward (label to number) and reverse (number to label) lookups to increase its flexibility.hs.eventtap.event.newKeyEventSequence(modifiers, character) -> table
modifiers
table must contain the full name of the modifiers you wish used for the keystroke as defined in hs.keycodes.map
-- the Unicode equivalents are not supported by this function.hs.eventtap.event:copy() -> event
hs.eventtap.event
event for further modification or injectionhs.eventtap.event
objecths.eventtap.event.newEvent() -> event
hs.eventtap.event
objecths.eventtap.event.newEventFromData(data) -> event
hs.eventtap.event
object or nil if the string did not represent a valid evenths.eventtap.event.newGesture(gestureType[, gestureValue]) -> event
hs.eventtap.event
object or nil
if the gestureType
is not valid.beginMagnify
- Starts a magnification event with an optional magnification value as a number (defaults to 0). The exact unit of measurement is unknown.endMagnify
- Starts a magnification event with an optional magnification value as a number (defaults to 0.1). The exact unit of measurement is unknown.beginRotate
- Starts a rotation event with an rotation value in degrees (i.e. a value of 45 turns it 45 degrees left - defaults to 0).endRotate
- Starts a rotation event with an rotation value in degrees (i.e. a value of 45 turns it 45 degrees left - defaults to 45).beginSwipeLeft
- Begin a swipe left.endSwipeLeft
- End a swipe left.beginSwipeRight
- Begin a swipe right.endSwipeRight
- End a swipe right.beginSwipeUp
- Begin a swipe up.endSwipeUp
- End a swipe up.beginSwipeDown
- Begin a swipe down.endSwipeDown
- End a swipe down.hs.eventtap.event.newKeyEvent([mods], key, isdown) -> event
hs.hotkey
for more information) or an integer specifying the virtual keycode for the key.hs.eventtap.event
objectflagsChanged
and keyUp
/keyDown
events into one. This approach is still supported for backwards compatibility and because it does work in most cases.flagsChanged
events without a corresponding keyUp
or keyDown
, please check out the syntax demonstrated above.~~~lua hs.eventtap.event.newKeyEvent({"shift", "alt"}, "a", true):post() hs.eventtap.event.newKeyEvent({"shift", "alt"}, "a", false):post()~~~hs.eventtap.event.newMouseEvent(eventtype, point[, modifiers) -> event
hs.eventtap.event.types
{x=123, y=456}
) indicating the location where the mouse event should occurhs.eventtap
objecths.eventtap.event.newScrollEvent(offsets, mods, unit) -> event
hs.eventtap.event
objecths.eventtap.event.newSystemKeyEvent(key, isdown) -> event
hs.eventtap.event
objecths.eventtap.event:setFlags()
methodhs.eventtap.event:asData() -> string
hs.eventtap.event:getButtonState(button) -> bool
hs.eventtap.event:getCharacters([clean]) -> string or nil
false
, which indicates if key modifiers, other than Shift, should be stripped from the keypress before converting to Unicode.clean
is true, all modifiers except for Shift are stripped from the character before converting to the Unicode character represented by the keypress.clean
is false, then Opt-E will return an empty string, while Opt-Shift-E will return an accent mark).hs.eventtap.event:getFlags() -> table
true
:hs.eventtap.event:getKeyCode() -> keycode
hs.keycodes.map
hs.eventtap.event:getProperty(prop) -> number
hs.eventtap.event.properties
CGEventField
values, as documented at https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/index.html#//apple_ref/c/tdef/CGEventFieldhs.eventtap.event:getRawEventData() -> table
CGEventData
is already available through other methods, but is presented here without any cleanup or parsing.hs.eventtap.event:getTouchDetails() -> table | nil
| | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Returns a table contining more information about some touch related events. | | Parameters |hs.eventtap.event.types.gesture
), then this method returns a table with zero or more of the following key-value pairs:pressure
- a number between 0.0 and 1.0 inclusive indicating the relative amount of pressure applied by the touch; trackpads which are not pressure sensitive will only report the discrete values of 0.0 and 1.0.stage
- an integer between 0 and 2 specifying the stage. 0 represents a touch transitioning to a state too light to be considered a touch, usually at the end of a click; 1 represents a touch with enough pressure to be considered a mouseDown event; 2 represents additional pressure, usually what would trigger a "deep" or "force" touch.stageTransition
- a number between 0.0 and 1.0. As the pressure increases and transition between stages begins, this will rise from 0.0 to 1.0; as the pressure decreases and a transition between stages begins, this will fall from 0.0 to -1.0. When the pressure is solidly within a specific stage, this will remain 0.0.pressureBehavior
- a string specifying the effect or purpose of the pressure. Note that the exact meaning (in terms of haptic feedback or action being performed) of each label is target application or ui element specific. Valid values for this key are:magnification
- a number specifying the change in magnification that should be added to the current scaling of an item to achieve the new scale factor.rotation
- a number specifying in degrees the change in rotation that should be added as specified by this event. Clockwise rotation is indicated by a negative number while counter-clockwise rotation will be positive.hs.eventtap.event:getTouches() -> table | nil
| | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Returns a table of details containing information about touches on the trackpad associated with this event if the event is of the type hs.eventtap.event.types.gesture
. | | Parameters |device
- a string containing a unique identifier for the device on which the touch occurred. At present we do not have a way to match the identifier to a specific touch device, but if multiple such devices are attached to the computer, this value will differ between them.deviceSize
- a size table containing keys h
and w
for the height and width of the touch device in points (72 PPI resolution).force
- a number representing a measure of the force of the touch when the device is a forcetouch trackpad. This will be 0.0 for non-forcetouch trackpads and the touchbar.identity
- a string specifying a unique identifier for the touch guaranteed to be unique for the life of the touch. This identifier may be used to track the movement of a specific touch (e.g. finger) as it moves through successive callbacks.phase
- a string specifying the current phase the touch is considered to be in. The possible values are: "began", "moved", "stationary", "ended", or "cancelled".resting
- Resting touches occur when a user simply rests their thumb on the trackpad device. Requires that the foreground window has views accepting resting touches.timestamp
- a number representing the time the touch was detected. This number corresponds to seconds since the last system boot, not including time the computer has been asleep. Comparable to hs.timer.absoluteTime() / 1000000000
.touching
- a boolean specifying whether or not the touch phase is "began", "moved", or "stationary" (i.e. is not "ended" or "cancelled").type
- a string specifying the type of touch. A "direct" touch will indicate a touchbar, while a trackpad will report "indirect".hs.eventtap.event:getType([nsSpecificType]) -> number
nsSpecificType
- an optional boolean, default false, specifying whether or not a more specific Cocoa NSEvent type should be returned, if available.hs.eventtap.event.types
hs.eventtap.event.types.gesture
event. For example:hs.eventtap.event:getUnicodeString()
hs.eventtap.event:location([pointTable]) -> event | table
| | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Get or set the current mouse pointer location as defined for the event. | | Parameters |hs.eventtap.event
object; otherwise returns a point table containing x and y key-value pairs specifying the mouse pointer location as specified for this event.hs.eventtap.event:post([app])
hs.application
object. If specified, the event will only be sent to that applicationhs.eventtap.event
objecths.eventtap.event:rawFlags([flags]) -> event | integer
| | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Experimental method to get or set the modifier flags for an event directly. | | Parameters |hs.eventtap.event
object; otherwise returns the current flags set as an integerhs.eventtap.event:setFlags(table) -> event
true
:hs.eventap.event
object.hs.eventtap.event:setKeyCode(keycode)
hs.keycodes.map
hs.eventtap.event
objecths.eventtap.event:setProperty(prop, value)
hs.eventtap.event.properties
hs.eventtap.event
object.CGEventField
values, as documented at https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/index.html#//apple_ref/c/tdef/CGEventFieldhs.eventtap.event:setType(type) -> event
hs.eventtap.event
objecths.eventtap.event:setUnicodeString(string)
hs.eventtap.event
objecths.eventtap.event:systemKey() -> table
key
./System/Library/Frameworks/IOKit.framework/Headers/hidsystem/ev_keymap.h
. If you believe the numeric value is part of a new system update or was otherwise mistakenly left out, please submit the label (it will defined in the header file as NX_KEYTYPE_something
) and number to the Hammerspoon maintainers at https://github.com/Hammerspoon/hammerspoon with a request for inclusion in the next Hammerspoon update.hs.eventtap.event:timestamp([absolutetime]) -> event | integer
| | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Get or set the timestamp of the event. | | Parameters |hs.eventtap.event
object; otherwise returns the current timestamp for the event.hs.timer.absoluteTime
.