Page 1 of 1

Need equivalent of inkey$ in windows

Posted: Sat Mar 19, 2005 8:08 am
by chippy73
I need to detect if any key has been pressed during a set period, say 15 secs.

I looked at GetAsyncKeyState and others in the API group, but couldn't find anything for ANY key, only specific keys.

The PB keyboard commands are, I believe only for Console screens so that's no good. I need to detect any key pressed in windows during a period of say, 15secs.

Any comments welcomed.

Alan

Posted: Sat Mar 19, 2005 9:32 am
by chippy73
I think I may have solved it but the secs variable is not incrementing.

I have this before the main loop.

Code: Select all

Procedure UpdateTime(Value)
  Repeat
    secs=secs+1
    Delay(1000)
  Until quitForm1=1
EndProcedure

thd=CreateThread(@UpdateTime(),0)
Then this inside the main loop before the repeat - until stuff

Code: Select all

If secs>15
    do something
  EndIf

Alan

Re: Need equivalent of inkey$ in windows

Posted: Sat Mar 19, 2005 11:20 am
by PB

Code: Select all

Procedure KeyPressed()
  For k=8 To 123 ; A-Z, 0-9, F1-F12, Numpad, Backspace, etc.
    If GetAsyncKeyState_(k)<>0
      Repeat : Delay(1) : Until GetAsyncKeyState_(k)=0
      r=1 : Break ; Exit loop now since we're done.
    EndIf
  Next
  ProcedureReturn r
EndProcedure

Repeat

  Delay(1)
  
  If KeyPressed()=1
    Debug "A key has been pressed!"
  EndIf

ForEver

Posted: Sat Mar 19, 2005 2:03 pm
by chippy73
Thanks PB,

That will do the job nicely.

Alan

P.S. found why the counter wasnt incrementing.I forgot to declare a variable in a procedure as global.