mouse - winnichenko/BLOB-87 GitHub Wiki
mouse
mouse -> x y left middle right scrollx scrolly
Output
- x : x coordinate of the mouse pointer
- y : y coordinate 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)
Description
This function returns the mouse coordinates and a boolean value for the state of each mouse button, with true indicating that a button is pressed.
Reference
Example
-- title: mouse position and buttons
-- author: PaulR
-- script: lua
-- input: mouse
function TIC()
local x,y,left,middle,right,scrollx,scrolly=mouse()
cls(1)
print('Position '..string.format('x=%03i y=%03i',x,y),10,10)
print('Left '..tostring(left),10,20)
print('Middle '..tostring(middle),10,40)
print('Right '..tostring(right),10,30)
print('ScrollX '..tostring(scrollx),10,50)
print('ScrollY '..tostring(scrolly),10,60)
-- Note: ScrollX/ScrollY will be available in TIC-80 0.80.0+
end
Example
-- 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
Example
-- 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