event

Last updated 23 days ago

Create, modify and inspect events for hs.eventtap

This module is based primarily on code from the previous incarnation of Mjolnir by Steven Degutis.

API Overview

API Documentation

Constants

Signature

hs.eventtap.event.properties -> table

Type

Constant

Description

A table containing property types for use with 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.

Notes

Signature

hs.eventtap.event.rawFlagMasks[]

Type

Constant

Description

A table containing key-value pairs describing the raw modifier flags which can be manipulated with hs.eventtap.event:rawFlags.

types

Signature

hs.eventtap.event.types -> table

Type

Constant

Description

A table containing event types to be used with 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.

Notes

Functions

Signature

hs.eventtap.event.newKeyEventSequence(modifiers, character) -> table

Type

Function

Description

Generates a table containing the keydown and keyup events to generate the keystroke with the specified modifiers.

Parameters

Returns

Notes

Constructors

copy

Signature

hs.eventtap.event:copy() -> event

Type

Constructor

Description

Duplicates an hs.eventtap.event event for further modification or injection

Parameters

Returns

newEvent

Signature

hs.eventtap.event.newEvent() -> event

Type

Constructor

Description

Creates a blank event. You will need to set its type with hs.eventtap.event:setType

Parameters

Returns

Notes

Signature

hs.eventtap.event.newEventFromData(data) -> event

Type

Constructor

Description

Creates an event from the data encoded in the string provided.

Parameters

Returns

Signature

hs.eventtap.event.newKeyEvent([mods], key, isdown) -> event

Type

Constructor

Description

Creates a keyboard event

Parameters

Returns

Notes

Signature

hs.eventtap.event.newMouseEvent(eventtype, point[, modifiers) -> event

Type

Constructor

Description

Creates a new mouse event

Parameters

Returns

Signature

hs.eventtap.event.newScrollEvent(offsets, mods, unit) -> event

Type

Constructor

Description

Creates a scroll wheel event

Parameters

Returns

Signature

hs.eventtap.event.newSystemKeyEvent(key, isdown) -> event

Type

Constructor

Description

Creates a keyboard event for special keys (e.g. media playback)

Parameters

Returns

Notes

Methods

asData

Signature

hs.eventtap.event:asData() -> string

Type

Method

Description

Returns a string containing binary data representing the event. This can be used to record events for later use.

Parameters

Returns

Notes

Signature

hs.eventtap.event:getButtonState(button) -> bool

Type

Method

Description

Gets the state of a mouse button in the event

Parameters

Returns

Notes

Signature

hs.eventtap.event:getCharacters([clean]) -> string or nil

Type

Method

Description

Returns the Unicode character, if any, represented by a keyDown or keyUp event.

Parameters

Returns

Notes

getFlags

Signature

hs.eventtap.event:getFlags() -> table

Type

Method

Description

Gets the keyboard modifiers of an event

Parameters

Returns

Signature

hs.eventtap.event:getKeyCode() -> keycode

Type

Method

Description

Gets the raw keycode for the event

Parameters

Returns

Notes

Signature

hs.eventtap.event:getProperty(prop) -> number

Type

Method

Description

Gets a property of the event

Parameters

Returns

Notes

Signature

hs.eventtap.event:getRawEventData() -> table

Type

Method

Description

Returns raw data about the event

Parameters

Returns

Notes

getType

Signature

hs.eventtap.event:getType() -> number

Type

Method

Description

Gets the type of the event

Parameters

Returns

location

Signature

`hs.eventtap.event:location([pointTable]) -> event

table` </span>

Type

Method

Description

Get or set the current mouse pointer location as defined for the event.

Parameters

Returns

Notes

post

Signature

hs.eventtap.event:post([app])

Type

Method

Description

Posts the event to the OS - i.e. emits the keyboard/mouse input defined by the event

Parameters

Returns

rawFlags

Signature

`hs.eventtap.event:rawFlags([flags]) -> event

integer` </span>

Type

Method

Description

Experimental method to get or set the modifier flags for an event directly.

Parameters

Returns

Notes

setFlags

Signature

hs.eventtap.event:setFlags(table) -> event

Type

Method

Description

Sets the keyboard modifiers of an event

Parameters

Returns

Signature

hs.eventtap.event:setKeyCode(keycode)

Type

Method

Description

Sets the raw keycode for the event

Parameters

Returns

Notes

Signature

hs.eventtap.event:setProperty(prop, value)

Type

Method

Description

Sets a property of the event

Parameters

Returns

Notes

setType

Signature

hs.eventtap.event:setType(type) -> event

Type

Method

Description

Set the type for this event.

Parameters

Returns

systemKey

Signature

hs.eventtap.event:systemKey() -> table

Type

Method

Description

Returns the special key and its state if the event is a NSSystemDefined event of subtype AUX_CONTROL_BUTTONS (special-key pressed)

Parameters

Returns

Notes

timestamp

Signature

`hs.eventtap.event:timestamp([absolutetime]) -> event

integer` </span>

Type

Method

Description

Get or set the timestamp of the event.

Parameters

Returns

Notes