1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 13:28:33 +00:00
13
LUA Events
Robert Beekman edited this page 2017-09-12 14:15:27 +02:00

Within the LUA environment you can use events to react to certain things, such as a device being updated or a key being pressed.

To use events you need to subscribe to them. You can subscribe to the same event more than once if you want.
The examples below show how subscribing works.

Overview

Events

DeviceUpdating

Triggers whenever a device is being updated. Use this event to process your own changes before every frame.
If you want to change the way a layer is drawn, this is a good place to do so.
Note: This event triggers for every device each frame. This means it can trigger 6 times, 25 times a second.

Parameters

profile profile, profileUpdatingEventArgs eventArgs

Event Arguments

  • DeviceType: An string describing the device type (keyboard, mouse, headset, generic or mousemat).
  • DataModel: An object containing the current DataModel. (TODO: DataModel explaination)
  • Preview: A boolean indicating whether the draw was done as a preview (for the editor).

Example

-- This function will be called after every profile update, before every profile draw.
function updateHandler(profile, eventArgs)
    -- In this example we only want to update once per frame when the keyboard is updated
    if not (eventArgs.DeviceType == "keyboard") then
        return
    end

    -- The Event Arguments are inside the eventArgs parameter
    -- In a Windows Profile, you could do this:
    local currentSong = eventArgs.DataModel.Spotify.SongName
end

-- Subscribe to the event AFTER defining the function which must be subscribed.
Events.DeviceDrawing.add(updateHandler)

DeviceDrawing

Triggers whenever there is being drawn to a device. Use this event to draw your own shapes after every frame.
For more info on drawing, see the Drawing page.
Note: This event triggers for every device each frame. This means it can trigger 6 times, 25 times a second.

Parameters

profile profile, profileDrawingEventArgs eventArgs

Event Arguments

  • DeviceType: An string describing the device type (keyboard, mouse, headset, generic or mousemat).
  • DataModel: An object containing the current DataModel. (TODO: DataModel explaination)
  • Preview: A boolean indicating whether the draw was done as a preview (for the editor).
  • Drawing: The Drawing object for this frame. Use this to draw your own shapes.

Example

-- This function will be called after every profile draw.
function drawHandler(profile, eventArgs)
    -- In this example we only want to draw to the keyboard
    if not (eventArgs.DeviceType == "keyboard") then
        return
    end
	
    -- The Event Arguments are inside the eventArgs parameter
    -- In a Windows Profile, you could do this:
    local currentSong = eventArgs.DataModel.Spotify.SongName
end

-- Subscribe to the event AFTER defining the function which must be subscribed.
Events.DeviceDrawing.add(drawHandler)

KeyboardKeyPressed

Triggers whenever the user presses a key.

Parameters

profile profile, keyPressEventArgs eventArgs

Event Arguments

  • Key: The key that was pressed, for a list of possible keys, see MSDN.
  • X: The X-position of the key on the current keyboard
  • Y: The Y-position of the key on the current keyboard

Example

-- This function will be called after every key press.
function keyHandler(profile, eventArgs)
    print("You pressed: " .. eventArgs.Key)
end

-- Subscribe to the event AFTER defining the function which must be subscribed.
Events.KeyboardKeyPressed.add(keyHandler)