wait for any input comming from keyboard or mouse

Previous topic - Next topic

kaotiklabs


Hi,

I would like to know if there?s a way I could do something similar to this:

Code (glbasic) Select
KEYWAIT OR MOUSEWAIT

You know, wait for any input comming from those devices without mattering if it comes from one or other.

Thanks!

Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Moru

This is one way to do it, just include the functions in your code and where you want to wait for any key you just call the wait_for_any_key() function. You can also call the any_key() function in your own game loop if you want to update animations while waiting for a key- or buttonpress.

Code (glbasic) Select
PRINT "Hello, press any key or mouse-button to quit", 50, 50
SHOWSCREEN
wait_for_anykey()
END

FUNCTION wait_for_anykey:

WHILE any_key() = FALSE
SLEEP 50 // do a little waiting
WEND
ENDFUNCTION

FUNCTION any_key:
LOCAL a$, x, y, b1, b2

a$ = INKEY$()
MOUSESTATE x, y, b1, b2

// If anything pressed then return true
IF a$ <> "" OR b1 <> 0 OR b2 <> 0 THEN RETURN TRUE

// if nothing pressed, return false
RETURN FALSE
ENDFUNCTION

kaotiklabs


Many thanks Moru for the quick answer!!

Worked like a charm.  :good:
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!