lee
New Member
Posts: 5
|
Post by lee on Jul 26, 2019 21:05:49 GMT -5
I would like to use INKEY$ in my code. I see that "Keyboard input can only be trapped in graphics windows or graphicboxes" Is there a work around when I am not using graphics that would allow me to get a key from the keyboard while the code is running but not stop when there is no key press?
|
|
|
Post by tsh73 on Jul 27, 2019 2:57:24 GMT -5
|
|
|
Post by Rod on Jul 27, 2019 3:05:12 GMT -5
Yep, real simple code demo. Press Esc to stop the program. It shows the different responses that a key press gives. 0 not been pressed. 1 currently pressed. and -x pressed and released since last checked. You need to check the keystate on a smoothly timed basis else the user feels the system isn't responding. This checks keys 1-6 and Esc. The names of all the keys are listed here. Place a _ ahead of the name docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes timer 400, [keyCheck] wait
[keyCheck] if keyState(27)>0 then goto [quit] cls print "1 ";keyState(49),"2 ";keyState(50),"3 ";keyState(51),"4 ";keyState(52),"5 ";keyState(53),"6 ";keyState(54) wait
[quit] timer 0 print "program ended" end
function keyState(keycode) calldll #user32, "GetAsyncKeyState", _ keycode AS long, _ keyState AS long end function
|
|
|
Post by Gordon Rahman on Jul 28, 2019 16:14:47 GMT -5
I would like to use INKEY$ in my code. I see that "Keyboard input can only be trapped in graphics windows or graphicboxes" Is there a work around when I am not using graphics that would allow me to get a key from the keyboard while the code is running but not stop when there is no key press? [main]
CLS
print "THIS IS A TEST"
print "PLEASE HIT ANY key to continue"
gosub [getanykey]
print "thanks you hit any key"
print " .... LOL ";getkey$
end
[getanykey]
getkey$ = input$(1)
return
'---code end
So the work around is to use input$(1) Gordon
|
|
|
Post by Rod on Jul 29, 2019 2:56:12 GMT -5
I don't think this is the solution sought. It does stop at input$(1) The OP wanted something akin to the original inkey$ command which checked for input, returned a key if there was one pressed or simply moving on if there were none.
[main]
CLS
print "THIS IS A TEST"
print "PLEASE HIT ANY key to continue"
gosub [getanykey]
print "thanks you hit any key"
print " .... LOL ";getkey$
end
[getanykey] print "We are waiting for input" getkey$ = input$(1) print "Got input moving on." return
'---code end
|
|
|
Post by Gordon Rahman on Jul 29, 2019 9:20:53 GMT -5
hmmm .... this teaches me to read the question of the OP much more carefully. I use Inkey$ as part of the "when chracterInput" event. and with Inkey$ I can read all keys of my keyboard.
|
|
|
Post by alincon on Jul 29, 2019 18:52:06 GMT -5
Isn't it possible to open an off-screen graphics window, or have a graphics box with all dimensions = 0 in order to enable Inkey$?
r.m.
|
|
|
Post by tsh73 on Jul 30, 2019 3:03:53 GMT -5
Graphics / graphics box needs to have focus ("setfocus") for INKEY to work. Any time you click on button/edit field/whatever, focus will be lost and INKEY will stop working.
|
|