For things like input, I tend to avoid polling the the mouse() keystates through out the program. While they can be surprising hogs at times, this mainly solves a common logic problem where the user can select multiple things during one refresh. Which occurs because the mouse can have moved between calls.
Preferring to grab the key & mouse states (X,y,buttons) into a type at the start of each refresh.
(PB formatted code, change to suit)
// declaration code
Type tMouseState
x,y,button
EndType
Type tKeyBoardState
somekey
EndType
Type tInputDevices
Mouse as tMouseState
KeyBoard as tKeyBoardState
EndType
// Store in a global type, protecting us from typos
Dim Input as tInputDevices
// main loop
do
// Get the mouse state
Input.Mouse.x =MouseX()
Input.Mouse.y =MouseY()
Input.Mouse.button =MouseButton()
// Call the game stuff
DoGameStuff()
sync
loop
function DoGameStuff()
if Input.mouse.button
print "Fire"
// flush the state
Input.mouse.button=0
endif
endfunction
So the states are global but are stored in a type structure.