Skip to content
Vadim Grigoruk edited this page Nov 22, 2026 · 26 revisions
  • btnp(id, [hold], [period]) -> is_pressed
  • btnp() -> GAMEPADS data

Parameters

  • id : the id (0..31) of the button we wish to interrogate - see the key map for reference
  • hold : the time (in ticks) the button must be pressed before re-checking
  • period : the amount of time (in ticks) after hold before this function will return true again.

Returns

  • is_pressed : button is pressed now but not in previous frame (true/false)
  • GAMEPADS data : 32-bit mask of the buttons that were pressed in this frame and were not held in the previous one (~previous & current, see RAM).

Description

This function allows you to read the status of one of TIC's buttons. It returns true only if the key has been pressed since the last frame.

You can also use the optional hold and period parameters which allow you to check if a button is being held down. After the time specified by hold has elapsed, btnp will return true each time period is passed if the key is still down. For example, to re-examine the state of button '0' after 2 seconds and continue to check its state every 1/10th of a second, you would use btnp(0, 120, 6). Since time is expressed in ticks and TIC runs at 60 frames per second, we use the value of 120 to wait 2 seconds and 6 ticks (ie 60/10) as the interval for re-checking.

Input Tag

Set the metadata input tag to gamepad to display only the on-screen gamepad on Android devices and hide the keyboard.

Example

Example

-- btnp demo: move the rectangle in 10 pixels step,
-- every time one direction keys is pressed.
-- Keep the key pressed for more than 1 second to have
-- the rectangle move every tenth of seconds.

x=120
y=80

cls(12)
function TIC()

    if btnp(0,60,6) then y=y-10 end
    if btnp(1,60,6) then y=y+10 end
    if btnp(2,60,6) then x=x-10 end
    if btnp(3,60,6) then x=x+10 end

    rect(x,y,10,10,8)
end

Home
Tips for newcomers

Built-in Editors

Code | Sprites | Maps | SFX | Music

Console

All commands

save | export | load | import | menu | config | surf | shelf | demo | eval 

Platform

RAM | VRAM | Display | Palette | Bits per Pixel (BPP) | .tic Format | Supported Languages

Other

Tutorials | Code Snippets | Libraries | External Tools | FFT


API

All API functions

Callbacks

TIC | BOOT | MENU | BDR

  • SCN (deprecated)
  • OVR (deprecated)

Input

btn | btnp | btnr | key | keyp | keyr | mouse

Drawing

circ | circb | clip | cls | elli | ellib | font | line | map | paint | pix | print | rect | rectb | rrect | rrectb | spr | tri | trib | ttri | fill patterns

Sound

music | sfx | FFT | VQT

Memory

memcpy | memset | mget | mset | peek | poke | pmem | sync | vbank

System

exit | reset | time | tstamp | trace

Clone this wiki locally