detecting a keystroke in console?

BlitzPlus Forums/BlitzPlus Programming/detecting a keystroke in console?

Rodvik(Posted 2003) [#1]
UPDATE:

Well it appears that console does not support any commands other than print or input.
From the manual :
"The following program demonstrates the use of the two BlitzPlus console commands Print and Input."

I will leave this message here in case others run into the same issue.


old message--------------------------------------


Any help would be appreciated. I am working on a text game which I would like to be console rather than printing text to a window.

However I have been unable to get getkey() to work using console.

In the following example if the graphics mode line is commented out then a keystroke is never detected. If it remains the keystroke is only ever detected if the blank graphics window is selected rather than the console window.

Any advice would be welcomed.

Thanks in adavnce


;***********************START CODE**************************
Graphics 800,600,16,2 ; set resolution, if this is removed, console displays but keys never detected.



;***********************MAIN MENU********************************
.mainmenu ; start of main menu loop

.statusreturn
FlushKeys
Print seasonname$
Print "1 status"
Print "2 recruit"
Print "3 war"
Print "4 peace"
Print "5 trade"
Print "6 revelry"
Print "9 quit"


;.waitforkey
WaitKey()
If KeyDown(2) Then Print "status";if key detected then print selected option
If KeyDown(3) Then Print "recruit"
If KeyDown(4) Then Print "who_attack"
If KeyDown(5) Then Print "peace"
If KeyDown(6) Then Print "trade"
If KeyDown(7) Then Print "revelry"
If KeyDown(10) Then End
Goto statusreturn

End


soja(Posted 2003) [#2]
quick idea: find a similar function to KeyDown in the Windows API and use it via a userlib?

(I seem to remember seeing something like that... maybe it would work. I can't check right now though.)


soja(Posted 2003) [#3]
Na, nevermind. I tried it with GetKeyboardState (user32) and it didn't work. (Likely, Blitz detects keystrokes with a similar function.)

I think the only way to do it would be to write a dll yourself that sets s system-wide keyboard hook with a callback function and monitors what keys get hit while the console is in the foreground and returns the results to your program.

But that would be a big pain.


Rodvik(Posted 2003) [#4]
Thanks Soja

Yeah I spoke with a freind about hit. He expalined that the reason it works with another window open is its using the windows keyboard que but in theory you can pull the ketstrokes as well in C++ at least.

Anyhow I am going to make my own life easier and just convert the whole thing to a windows app with B+ running in a fancy windows window instead of console.


skn3(Posted 2003) [#5]
Why not use make your own console, using a text area ?


Rodvik(Posted 2003) [#6]
skn3:

Thats probably what I will end up doing.

Somewhat bizzarely I wanted a really "old school" feel to the text display and console fitted the bill really well.

Ah well I'll just get the feeling another way.


CdrJameson(Posted 2003) [#7]
Whoops, I've just run into this too. Again, it'd be nice to point out in the man page for waitkey that it doesn't work for console apps