'=========================================================================== ' Subject: QB SIMULTANEOUS KEY Date: Unknown Date (00:00) ' Author: Brent Ashley Code: ASM, QB, PDS ' Keys: QB,SIMULTANEOUS,KEY Packet: KEYBOARD.ABC '=========================================================================== 'BASIC test code: DECLARE FUNCTION KeyPressed%(ScanCode%) CALL InstKeyPress ' install resident code CLS DO LOCATE 1,1 FOR i% = 2 TO 9 ' scancode of 1 to 8 IF KeyPressed(i%) THEN PRINT CHR$(47+i%); ELSE PRINT " "; NEXT PRINT LOOP UNTIL INKEY$=CHR$(27) ' escape to quit CALL UnHookKeyPress ' unhook resident code - IMPORTANT!!! END ; KeyPress.ASM by Brent Ashley ; checks the "pressed" status of any key .model medium, basic .code Old09 Label Dword ;Label for to old Int 09h handler Old09Offset dw ? ;Offset part Old09Segment dw ? ;Segment part Hooked db 0 ;Our installed flag KeyMap db 80 dup(0) ;map of kybd, one byte per scancode InstKeyPress proc uses ds ax dx ; From BASIC: CALL InstKeyPress ; REMEMBER to call UnhookKeyPress! cmp cs:Hooked,0 ;Are we already hooked? jnz InstallExit ;If so, exit mov ax,3509h ;Get current vector for int 09h int 21h mov cs:Old09Segment,es ;Remember it for later mov cs:Old09Offset,bx mov ax,2509h push ds push cs pop ds ;Point int 09h handler to our code mov dx, offset OurInt09 int 21h pop ds mov cs:Hooked,-1 ;Set our installed flag InstallExit: ret OurInt09: ;Our Int 09h handler push ax push bx push dx push si in al, 60h test al, 080h ;is "released" bit set? jnz Released ;yup - go to it mov dl, 0FFh ;nope - set key pressed flag jmp PutFlag Released: and al, 07Fh ;yes - clear bit for index mov dl, 0 ;and set flag for release PutFlag: xor ah, ah mov si, ax ;assign index mov cs:KeyMap[si], dl ;put flag in place pop si pop dx pop bx pop ax Continue: jmp dword ptr cs:[Old09];Transfer ctrl to orig Int 09h InstKeyPress endp KeyPressed proc uses bx si, ScanCode:WORD ; from BASIC: TrueOrFalse% = KeyPressed(ScanCode%) mov bx, ScanCode ;get scan code addr mov si, [bx] ;load value as index mov al, cs:KeyMap[si] ;put flag in al cbw ;convert to word for integer value ret KeyPressed endp UnhookKeyPress proc ; from BASIC: CALL UnHookKeyPress cmp cs:Hooked,0 ; are we installed? jz UnHooked ; nope - exit push ax push ds mov ax,2509h ;Unhook ourself mov ds,Old09Segment mov dx,Old09Offset int 21h ;Point Int 09h back to orig hndlr pop ds pop ax mov cs:Hooked,0 ;Set installed flag back to zero UnHooked: ret UnhookKeyPress endp END