mouse
TimotheeGreg edited this page Oct 16, 2023
·
22 revisions
mouse() -> x, y, left, middle, right, scrollx, scrolly
- x y : coordinates of the mouse pointer
- left : left button is down (true/false)
- middle : middle button is down (true/false)
- right : right button is down (true/false)
- scrollx : x scroll delta since last frame (-31..32)
- scrolly : y scroll delta since last frame (-31..32)
This function returns the mouse coordinates, a boolean value for the state of each mouse button (with true indicating that a button is pressed) and any change in the scroll wheel. Note that scrollx values are only returned for devices with a second scroll wheel, trackball etc.
Set the metadata input
tag to mouse
if you do not use btn/btnp or key/keyp to hide the on-screen gamepad and keyboard on Android devices.
-- title: mouse position and buttons
-- author: paul59
-- script: lua
-- input: mouse
local GR,YE,WH=6,4,12
local barx,bary=10,10
function TIC()
local x,y,left,middle,right,scrollx,scrolly=mouse()
barx=barx+scrollx
bary=bary+scrolly
if barx<1 then barx=1 end
if bary<1 then bary=1 end
cls(0)
print('Move Mouse:',10,10,YE)
print('Position '..string.format('x=%03i y=%03i',x,y),100,10,WH)
print('Press Buttons:',10,20,YE)
print('Left '..tostring(left),100,20,WH)
print('Middle '..tostring(middle),100,40,WH)
print('Right '..tostring(right),100,30,WH)
print('Scroll Wheel:',10,80,YE)
print('Scroll X',100,80,WH)
print('Scroll Y',160,80,WH)
rect(100,136/2-barx,8,barx,GR)
rect(160,136/2-bary,8,bary,GR)
end
-- title: mouse demo
-- author: Raidez
-- script: lua
-- input: mouse
t=0
x=104
y=24
function TIC()
mx,my,md=mouse() --get x,y and pressed
if md then
x=mx
y=my
end
cls(12)
spr(1+(t%60)/30,x,y,-1,4)
t=t+1
end
-- title: demo mouse
-- author: Filippo
-- desc: wiki demo mouse
-- script: lua
-- input: mouse
r=0
function TIC()
cls()
--get mouse info
x,y,p=mouse()
--if pressed
if p then r=r+2 end r=r-1
r=math.max(0, math.min(32, r))
--draw stuff
line(x,0,x,136,11)
line(0,y,240,y,11)
circ(x,y,r,11)
--show coordinates
c=string.format('(%03i,%03i)',x,y)
print(c,0,0,15,1)
end
TIC-80 tiny computer https://tic80.com | Twitter | Telegram | Terms
Built-in Editors
Console
Platform
RAM & VRAM | Display | Palette | Bits per Pixel (BPP) |
.tic
Format | Supported Languages
Other
API
- BDR (0.90)
- BOOT (1.0)
- MENU
- OVR (deprecated)
- SCN (deprecated)
- TIC
- btn & btnp
- circ & circb
- clip
- cls
- elli & ellib (0.90)
- exit
- fget & fset (0.80)
- font
- key & keyp
- line
- map
- memcpy & memset
- mget & mset
- mouse
- music
- peek, peek4
- peek1, peek2 (1.0)
- pix
- pmem
- poke, poke4
- poke1, poke2 (1.0)
- rect & rectb
- reset
- sfx
- spr
- sync
- ttri (1.0)
- time
- trace
- tri & trib (0.90)
- tstamp (0.80)
- vbank (1.0)