Skip to content

lcd.hasFocus

since 1.5.0

Return true if the current window has the focus, else false.

local focus = lcd.hasFocus()

Parameters

None.

Returns

focus (boolean)

Examples

local function paint(widget)
  local w, h = lcd.getWindowSize()
  if lcd.hasFocus() then
    lcd.color(lcd.themeColor(THEME_FOCUS_COLOR))
    lcd.drawRectangle(0, 0, w, h, 2)          -- show the pilot this widget takes input
  end
end

On the home screen a widget only receives key events while it has focus. See Events.

Real-world usage

Called 15 times across 5 open-source Ethos Lua projects. A few short excerpts:
if not lcd.hasFocus() then return false end

src/inav-dashboard/widget.lua:424

if category == EVT_KEY and lcd.hasFocus() then

src/dashx/widgets/dashboard/dashboard.lua:726

if widget.infoPanelVisible and category == EVT_KEY and lcd.hasFocus()

src/rfsuite/widgets/dashboard.lua:1893