OpenTX 2.3 Lua Reference Guide
  • OpenTX 2.3 Lua Reference Guide
  • Introduction
    • Acknowledgments
    • Getting Started
  • Part I - Script Type Overview
    • Mix Scripts
    • Telemetry Scripts
    • One-Time Scripts
    • Wizard Script
    • Function Scripts
    • Widget Scripts
    • Theme Scripts
  • Part II - OpenTX Lua API Programming Guide
    • Input Table Syntax
    • Output Table Syntax
    • Init Function Syntax
    • Run Function Syntax
    • Return Statement Syntax
    • Included Lua Libraries
      • io Library
        • io.open()
        • io.close()
        • io.read()
        • io.write()
        • io.seek()
  • Part III - OpenTX Lua API Reference
    • Constants
      • Key Event Constants
    • General Functions
      • GREY()
      • accessTelemetryPush()
      • chdir(directory)
      • crossfireTelemetryPop()
      • crossfireTelemetryPush()
      • defaultChannel(stick)
      • defaultStick(channel)
      • flushAudio()
      • getAvailableMemory()
      • getDateTime()
      • getFieldInfo(name)
      • getFlightMode(mode)
      • getGeneralSettings()
      • getGlobalTimer()
      • getRAS()
      • getRSSI()
      • getRotEncSpeed()
      • getRtcTime()
      • getTime()
      • getTxGPS()
      • getUsage()
      • getValue(source)
      • getVersion()
      • ghostTelemetryPop()
      • ghostTelemetryPush()
      • killEvents(key)
      • loadScript(file [, mode], [,env])
      • multiBuffer(address[,value])
      • playDuration(duration [, hourFormat])
      • playFile(name)
      • playHaptic(duration, pause [, flags])
      • playNumber(value, unit [, attributes])
      • playTone(frequency, duration, pause [, flags [, freqIncr]])
      • popupConfirmation(title, event)
      • popupInput(title, event, input, min, max)
      • popupWarning(title, event)
      • resetGlobalTimer([type])
      • serialRead([num])
      • serialWrite(str)
      • setTelemetryValue(id, subID, instance, value [, unit [, precision [, name]]])
      • setSerialBaudrate(baudrate)
      • sportTelemetryPop()
      • sportTelemetryPush()
    • Model Functions
      • model.defaultInputs()
      • model.deleteFlightModes()
      • model.deleteInput(input, line)
      • model.deleteInputs()
      • model.deleteMix(channel, line)
      • model.deleteMixes()
      • model.getCurve(curve)
      • model.getCustomFunction(function)
      • model.getFlightMode(index)
      • model.getGlobalVariable(index, flight_mode)
      • model.getInfo()
      • model.getInput(input, line)
      • model.getInputsCount(input)
      • model.getLogicalSwitch(switch)
      • model.getMix(channel, line)
      • model.getMixesCount(channel)
      • model.getModule(index)
      • model.getOutput(index)
      • model.getSensor(sensor)
      • model.getSwashRing(params)
      • model.getTimer(timer)
      • model.insertInput(input, line, value)
      • model.insertMix(channel, line, value)
      • model.resetSensor(sensor)
      • model.resetTimer(timer)
      • model.setCurve(curve, params)
      • model.setCustomFunction(function, value)
      • model.setFlightMode(index, params)
      • model.setGlobalVariable(index, flight_mode, value)
      • model.setInfo(value)
      • model.setLogicalSwitch(switch, value)
      • model.setModule(index, value)
      • model.setOutput(index, value)
      • model.setSwashRing(params)
      • model.setTimer(timer, value)
    • Lcd Functions
      • Lcd Functions Overview
      • lcd.RGB(r, g, b)
      • lcd.clear([color])
      • lcd.drawBitmap(bitmap, x, y [, scale])
      • lcd.drawChannel(x, y, source, flags)
      • lcd.drawCombobox(x, y, w, list, idx [, flags])
      • lcd.drawFilledRectangle(x, y, w, h [, flags])
      • lcd.drawGauge(x, y, w, h, fill, maxfill [, flags])
      • lcd.drawLine(x1, y1, x2, y2, pattern, flags)
      • lcd.drawNumber(x, y, value [, flags])
      • lcd.drawPixmap(x, y, name)
      • lcd.drawPoint(x, y)
      • lcd.drawRectangle(x, y, w, h [, flags [, t]])
      • lcd.drawScreenTitle(title, page, pages)
      • lcd.drawSource(x, y, source [, flags])
      • lcd.drawSwitch(x, y, switch, flags)
      • lcd.drawText(x, y, text [, flags])
      • lcd.drawTimer(x, y, value [, flags])
      • lcd.getColor(area)
      • lcd.getLastLeftPos()
      • lcd.getLastPos()
      • lcd.getLastRightPos()
      • lcd.refresh()
      • lcd.resetBacklightTimeout()
      • lcd.setColor(area, color)
    • Bitmap Functions
      • Bitmap.getSize(name)
      • Bitmap.open(name)
  • Part IV - Converting OpenTX 2.0 Scripts
    • General Issues
    • Handling GPS Sensor data
    • Handling Lipo Sensor Data
  • Part V - Converting OpenTX 2.1 Scripts
  • Part VI - Advanced Topics
    • Lua data sharing across scripts
    • Debugging techniques
    • Speed/memory optimizaton tricks
  • Part VII - Appendix
    • Fonts
    • Units
Powered by GitBook
On this page
  • The key event mechanism
  • Constants
  • Virtual events
  1. Part III - OpenTX Lua API Reference
  2. Constants

Key Event Constants

PreviousConstantsNextGeneral Functions

Last updated 3 years ago

This page describes the value that is passed to scripts in the event parameter. It is used in and scripts.

The key event mechanism

Each time a key is pressed, held and released a number of events get generated. Here is a typical flow:

  • when a key is pressed a FIRST event is generated

  • if the key continues to be pressed, then after a while a LONG event is generated

  • if the key continues to be pressed, then a REPEAT events are being generated

  • when the key is released a BREAK event is generated

Couple of examples:

  • a short press on key would generate: FIRST, BREAK

  • a longer pres on key would generate: FIRST, LONG, BREAK

  • even longer press: FIRST, LONG, REPEAT,REPEAT, ..., BREAK

This normal key event sequence can be altered with the function. Any time this function is called (after the FIRST event) all further key events for this key will be suppressed until the next key press of this key. Examples:

  • kill immediately after the key press would generate: FIRST

  • kill after the long key press would generate: FIRST, LONG

Constants

  • key number

  • type of event

The two fields are combined into one single number. Some of these combinations are defined as constants and are available to Lua scripts:

Key Event Name
Comments

EVT_MENU_BREAK

MENU key release

EVT_PAGE_BREAK

PAGE key release

EVT_PAGE_LONG

MENU key long press

EVT_ENTER_BREAK

ENT key release

EVT_ENTER_LONG

ENT key long press

EVT_EXIT_BREAK

EXIT key release

EVT_PLUS_BREAK

+ key release

EVT_MINUS_BREAK

- key release

EVT_PLUS_FIRST

+ key press

EVT_MINUS_FIRST

- key press

EVT_PLUS_REPT

+ key repeat

EVT_MINUS_REPT

- key repeat

Radios with rotary encoder (X7 and Horus) have also:

Key Event Name
Comments

EVT_ROT_BREAK

rotary encoder release

EVT_ROT_LONG

rotary encoder long press

EVT_ROT_LEFT

rotary encoder rotated left

EVT_ROT_RIGHT

rotary encoder rotated right

Virtual events

Given the large number of radios supported by OpenTX, and the large difference in keys available on those, a set of VIRTUAL KEYS has been defined and are mapped to best fit available hardware

Virtual Key Event Name
Comments

EVT_VIRTUAL_NEXT_PAGE

for PAGE navigation

EVT_VIRTUAL_PREVIOUS_PAGE

for PAGE navigation

EVT_VIRTUAL_ENTER

EVT_VIRTUAL_ENTER_LONG

EVT_VIRTUAL_MENU

EVT_VIRTUAL_MENU_LONG

EVT_VIRTUAL_NEXT

for FIELDS navigation

EVT_VIRTUAL_NEXT_REPT

for FIELDS navigation

EVT_VIRTUAL_PREVIOUS

for FIELDS navigation

EVT_VIRTUAL_PREV_REPT

for FIELDS navigation

EVT_VIRTUAL_INC

for VALUES navigation

EVT_VIRTUAL_INC_REPT

for VALUES navigation

EVT_VIRTUAL_DEC

for VALUES navigation

EVT_VIRTUAL_DEC_REPT

for VALUES navigation

The event parameter in the and scripts run function actually carries two pieces of information:

Telemetry
One-Time
killEvents(key)
Telemetry
One-Time