For those learning PICO-8, you may have heard that you can write carts that access the hardware mouse. While the information to do this is not readily apparent, I put together this simple demonstration program with remarks to show how you can do it by reading the position and both buttons of the device.
-- simple introduction to -- using stat(32,33,34) -- for reading the mouse -- by dw817 -- (08-01-19) -- -- poke(24365,1) -- enables keyboard + mouse -- -- stat(32) mouse-x position -- stat(33) mouse-y position -- stat(34) =1 if left button -- stat(34) =2 if right button -- stat(34) =3 both buttons -- -- flip() updates the screen cls() poke(24365,1) -- enable mouse c=7 repeat color(7) -- if right-button pressed, -- change plotting color if stat(34)==2 then c=c+1 if (c==16) c=1 -- if both buttons pressed, -- clear the screen elseif stat(34)==3 then cls() end -- read x+y position of mouse x=stat(32) y=stat(33) -- if left button pressed, -- draw on screen if stat(34)==1 then if ox!=nil then line(ox,oy,x,y,c) end ox=x oy=y else ox=nil end p=pget(x,y) pset(x,y,c) flip() pset(x,y,p) -- loop until press [esc] until forever |
Those who want to reword this OOPS are welcome to.
Hope This Helps !



Thanks for this helpful guide to mouse input. Would you consider adding a mouse wheel demo? Maybe that could select brush size.
[Please log in to post a comment]