GLBasic forum

Main forum => GLBasic - en => Topic started by: kaotiklabs on 2009-Jun-28

Title: wait for any input comming from keyboard or mouse
Post by: kaotiklabs on 2009-Jun-28

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!

Title: Re: wait for any input comming from keyboard or mouse
Post by: Moru on 2009-Jun-28
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
Title: Re: wait for any input comming from keyboard or mouse
Post by: kaotiklabs on 2009-Jun-28

Many thanks Moru for the quick answer!!

Worked like a charm.  :good: