Need equivalent of inkey$ in windows

Windows specific forum
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

Need equivalent of inkey$ in windows

Post 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
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

Post 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
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Need equivalent of inkey$ in windows

Post 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
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

Post 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.
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22
Post Reply