Posts: 6,419
Threads: 74
Joined: Mar 2002
INP takes a port number, and returns the number in that port.
Code:
IF INP(&H60)=1 THEN PRINT "ESC!"
Posts: 58
Threads: 6
Joined: Jun 2004
Posts: 58
Threads: 6
Joined: Jun 2004
so if it = 1, then it has been pressed?
Posts: 2,771
Threads: 96
Joined: Oct 2003
yes.
you can either use INP(96) or INP(&H60). I would recommend learning this before you get to know about multi key handlers. The theory behind the multikey handlers is quite complex.
Posts: 58
Threads: 6
Joined: Jun 2004
Posts: 58
Threads: 6
Joined: Jun 2004
weelllllll..... could you give me the code for muilty key and then give a short explination plse?
I think I can handle it
Posts: 2,771
Threads: 96
Joined: Oct 2003
ok
check out this thread:
http://forum.qbasicnews.com/viewtopic.php?t=5307
The theory: When a key is pressed, it emits a pressed code. the is basically the scancode(shown in the list before). THis is fine for checking if 1 key is pressed at a time. But of course, when two or more keys are held down, INP(96) can only give the scancode of one of the keys. so this is where the multikey comes in. It detects when a key is pressed, and also when the key is --released--- using a release code. The scancode + 128 = release code for that key. So when the scancode is recieved, the key is marked as being "on". when the release code is detected, the key is marked as being "off".
I suppose its not that complicated... =)
Posts: 58
Threads: 6
Joined: Jun 2004
thanks man. I will use that code in my programs now. my friends had been complaining that the current key thing SUCKED!
thanks! :lol:
Posts: 116
Threads: 5
Joined: Jul 2004
Quote:weelllllll..... could you give me the code for muilty key and then give a short explination plse?
I think I can handle it
Code:
CLS
DO
I = INP(&H60)
IF (I AND &H80) THEN
BOARD(I XOR &H80) = FALSE
ELSE
BOARD(I) = NOT FALSE
END IF
DEF SEG = &H40: POKE &H1C, PEEK(&H1A)
LOCATE 1, 1: PRINT "Arrow up: "; BOARD(72); " "
LOCATE 2, 1: PRINT "Arrow down: "; BOARD(80); " "
LOCATE 3, 1: PRINT "Arrow right: "; BOARD(77); " "
LOCATE 4, 1: PRINT "Arrow left: "; BOARD(75); " "
LOCATE 6, 1: PRINT "Esc to exit."
LOOP UNTIL BOARD(1)
Make sure Num Lock is off.
This works well for me, unless there's alot of time between the
key handler and the code calling it. (The keys will stick.)
Anyways, that's just a quick example, but I'm going to find a solution to the sticky key problem, sometime soon.
If I resolve this problem I'll post the code here.
Cya.
Posts: 4,307
Threads: 63
Joined: May 2003
Why dont you clear the keyboard buffer? The sticking problem will dissappear =P.