#
hs.eventtap.event
Create, modify and inspect events for hs.eventtap
This module is based primarily on code from the previous incarnation of Mjolnir by Steven Degutis.
hs.eventtap.event.newGesture
uses an external library by Calf Trail Software, LLC.
Touch Copyright (C) 2010 Calf Trail Software, LLC
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
API Overview
Constants - Useful values which cannot be changed
properties rawFlagMasks types
Functions - API calls offered directly by the extension
newKeyEventSequence
Constructors - API calls which return an object, typically one that offers API methods
copy newEvent newEventFromData newGesture newKeyEvent newMouseEvent newScrollEvent newSystemKeyEvent
Methods - API calls which can only be made on an object returned by a constructor
asData getButtonState getCharacters getFlags getKeyCode getProperty getRawEventData getTouchDetails getTouches getType getUnicodeString location post rawFlags setFlags setKeyCode setProperty setType setUnicodeString systemKey timestamp
#
API Documentation
#
Constants
#
properties
#
rawFlagMasks
#
types
#
Functions
#
newKeyEventSequence
#
Constructors
#
copy
#
newEvent
#
newEventFromData
#
newGesture
#
newKeyEvent
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.eventtap.event.newKeyEvent([mods], key, isdown) -> event
|
| Type | Constructor |
| Description | Creates a keyboard event |
| Parameters |
- mods - An optional table containing zero or more of the following: cmd alt shift ctrl fn
- key - A string containing the name of a key (see
hs.hotkey
for more information) or an integer specifying the virtual keycode for the key. - isdown - A boolean, true if the event should be a key-down, false if it should be a key-up
- An
hs.eventtap.event
object
- The original version of this constructor utilized a shortcut which merged
flagsChanged
andkeyUp
/keyDown
events into one. This approach is still supported for backwards compatibility and because it does work in most cases. - According to Apple Documentation, the proper way to perform a keypress with modifiers is through multiple key events; for example to generate 'Å', you should do the following:
- ~~~lua
- hs.eventtap.event.newKeyEvent(hs.keycodes.map.shift, true):post()
- hs.eventtap.event.newKeyEvent(hs.keycodes.map.alt, true):post()
- hs.eventtap.event.newKeyEvent("a", true):post()
- hs.eventtap.event.newKeyEvent("a", false):post()
- hs.eventtap.event.newKeyEvent(hs.keycodes.map.alt, false):post()
- hs.eventtap.event.newKeyEvent(hs.keycodes.map.shift, false):post()
- ~~~
- The shortcut method is still supported, though if you run into odd behavior or need to generate
flagsChanged
events without a correspondingkeyUp
orkeyDown
, 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()
- ~~~
- The shortcut approach is still limited to generating only the left version of modifiers.
#
newMouseEvent
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.eventtap.event.newMouseEvent(eventtype, point[, modifiers) -> event
|
| Type | Constructor |
| Description | Creates a new mouse event |
| Parameters |
- eventtype - One of the mouse related values from
hs.eventtap.event.types
- point - An hs.geometry point table (i.e. of the form
{x=123, y=456}
) indicating the location where the mouse event should occur - modifiers - An optional table (e.g. {"cmd", "alt"}) containing zero or more of the following keys: cmd alt shift ctrl fn
- An
hs.eventtap
object
#
newScrollEvent
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.eventtap.event.newScrollEvent(offsets, mods, unit) -> event
|
| Type | Constructor |
| Description | Creates a scroll wheel event |
| Parameters |
- offsets - A table containing the {horizontal, vertical} amount to scroll. Positive values scroll up or left, negative values scroll down or right.
- mods - A table containing zero or more of the following: cmd alt shift ctrl fn
- unit - An optional string containing the name of the unit for scrolling. Either "line" (the default) or "pixel"
- An
hs.eventtap.event
object
#
newSystemKeyEvent
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.eventtap.event.newSystemKeyEvent(key, isdown) -> event
|
| Type | Constructor |
| Description | Creates a keyboard event for special keys (e.g. media playback) |
| Parameters |
- key - A string containing the name of a special key. The possible names are: SOUND_UP SOUND_DOWN MUTE BRIGHTNESS_UP BRIGHTNESS_DOWN CONTRAST_UP CONTRAST_DOWN POWER LAUNCH_PANEL VIDMIRROR PLAY EJECT NEXT PREVIOUS FAST REWIND ILLUMINATION_UP ILLUMINATION_DOWN ILLUMINATION_TOGGLE CAPS_LOCK HELP NUM_LOCK
- isdown - A boolean, true if the event should be a key-down, false if it should be a key-up
- An
hs.eventtap.event
object
- To set modifiers on a system key event (e.g. cmd/ctrl/etc), see the
hs.eventtap.event:setFlags()
method - The event names are case sensitive
#
Methods
#
asData
#
getButtonState
#
getCharacters
#
getFlags
#
getKeyCode
#
getProperty
#
getRawEventData
#
getTouchDetails
#
getTouches
#
getType
#
getUnicodeString
#
location
#
post
#
rawFlags
#
setFlags
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.eventtap.event:setFlags(table) -> event
|
| Type | Method |
| Description | Sets the keyboard modifiers of an event |
| Parameters |
- A table containing the keyboard modifiers to be sent with the event - i.e. zero or more of the following keys, each with a value of
true
: cmd alt shift ctrl fn
- The
hs.eventap.event
object.