Hi, I am making a blitz compression program that I would like to run from the command line and so I want to use it in a console. However I get to a stage where it finishes compressing the file and it displays a compression report. From here I want the program to end once the user has acknowledges the completion by pressing any key. However, the WaitKey() command won't work in a console window. I have tried to get around it by drawing a small graphics window which waits for the "WaitKey()" event but it only works if that window is in focus so you have to click onto it from the console window. I would like to use a console window because I can write data to the screen and retreive user input using the "Input$()" command. Have you got any ideas as to how I could get the program to halt until any key is pressed? I could do it with an enter key by doing a Input$("") command but I would prefer it without doing this as people can therefore type things onto the screen.
Any help is greatly appreciated
Seb
You might try this in your event handler loop:
;main loop to handle events
Repeat
enterkey = GetAsyncKeyState($0D) ;if enter key just pressed then LSB of enterkey is set
seperatorkey = GetAsyncKeyState($6C) ;if numpad enter key just pressed then LSB of seperatorkey is set
tabkey = GetAsyncKeyState(9) ;if tab key just pressed then LSB of tabkey is set
If (tabkey Or enterkey Or seperatorkey) And 1 Then DoSomething() ;checks keys least sig. bit=1
event = WaitEvent()
If event = $401 ;gadget action
;etc...
which requires this declaration:
.lib "user32.dll"
GetAsyncKeyState%(virtualkeycode%):"GetAsyncKeyState"
Interesting ^_^ .. I never went into the depths of those userlibs. All the time I had lousy key events that lost focus.
But afaics it works with ascii codes (13 for [enter], 65 for [A] etc.).. how do I read out things like cursors, F-keys, pageUp/Dn, ins, del, home, alt/shift/ctrl combinations etc. etc.?
Found the cursors and stuff, but I can't seem to make a clean function that works like KeyHit and KeyDown.. meaning that I wish to know which key is *hit*, and which combikey(s) is/are *down*..
Anyone a suggestion?
fixed ^_^
'ave phun
window=CreateWindow("Non-focus-loosing keys - CS^TBL",0,0,550,280,0,1)
Global canvas=CreateCanvas(4,4,512,256,window)
SetBuffer CanvasBuffer(canvas)
Dim Keys(255)
Global Alt,Shift,Ctrl
Repeat
WaitEvent()
If EventID()=$803
quit=True
EndIf
Readkeys()
If Keys(37)
;If Shift
;If Ctrl
If Alt
x=x-7
EndIf
x=x-1
If x<0 x=0
Update(x)
EndIf
If Keys(39)
;If Shift
;If Ctrl
If Alt
x=x+7
EndIf
x=x+1
If x>127 x=127
Update(x)
EndIf
Until quit
End
Function Update(x)
SetBuffer CanvasBuffer(canvas)
Cls
Rect x*4,32,4,4,False
FlipCanvas canvas
End Function
Function Readkeys()
For t=0 To 15
Keys(t)=0
key=GetAsyncKeyState(t)
If (key And 1)
Keys(t)=1
EndIf
Next
For t=19 To 255
Keys(t)=0
key=GetAsyncKeyState(t)
If (key And 1)
Keys(t)=1
EndIf
Next
shiftkey=GetAsyncKeyState(16)
If shiftkey=-32767 ; down
Shift=1
EndIf
If Shift
If shiftkey=1 ; up
Shift=0
EndIf
If shiftkey=0 ; up
Shift=0
EndIf
EndIf
ctrlkey=GetAsyncKeyState(17)
If ctrlkey=-32767 ; down
Ctrl=1
EndIf
If Ctrl
If ctrlkey=1 ; up
Ctrl=0
EndIf
If ctrlkey=0 ; up
Ctrl=0
EndIf
EndIf
altkey=GetAsyncKeyState(18)
If altkey=-32767 ; down
Alt=1
EndIf
If Alt
If altkey=1 ; up
Alt=0
EndIf
If altkey=0 ; up
Alt=0
EndIf
EndIf
End Function