inkey() waits...

Just starting out? Need help? Post your questions and find answers here.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

inkey() waits...

Post by DoubleDutch »

the inkey() command seems to wait for an event, it only seems to function properly if the mouse is over the console window...

is there a way for inkey() to skip waiting for an event if the window is not being "looked at"....?
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Inkey() depends upon an OpenConsole()

Post by oldefoxx »

Inkey() only works if you have an OpenConsole(), and it does not wait for an input, but rather returns "" if no key is pressed, or the ASCII code of the key that is pressed. A good way to use it is as follows:

Code: Select all

OpenConsole()



Repeat
Until Inkey()>""
CloseConsole()
End

To get the same effect without using the console, take a look at KeyboardPushed() and the option to use #PB_Key_All to see if any key has been pressed.
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I think that you may have misunderstood...

What I meant was that I AM in console mode, but when you do an Inkey(), the program will wait an event - either a mouse movement or whatever - try it... here is a clip from the main loop of the program (in console mode)...

Repeat
PrintAt(72,1,FormatDate("%hh:%ii:%ss",Date()))
ConsoleLocate(29,21)
Ascii$=UCase((Left(Inkey(),1)))
Select Ascii$
Case "1"
DoECD()
DisplayMain()
Case "2"
DoPT1()
DisplayMain()
Case "3"
DoEXCD()
DisplayMain()
EndSelect
Until Ascii$=Chr(#ESC)
CloseConsole()

(the PrintAt bit is just a procedure i made)...
From the above code, you would expect the program to constantly update the time while waiting for a key, nope!
What it does is hang (if no mouse movement or keyboard responce), no screen update!...

It does work, however if you do move the mouse about the console screen, or press any key...

Any solutions?
Post Reply