箭头键的扫描代码

时间:2015-04-08 23:24:23

标签: assembly keyboard dosbox scancodes

下面的“processKey”功能用于识别您在键盘上按下的键,并根据按下的键执行某些操作。下面编程的所有键都可以工作。我需要在函数中添加检测四个箭头键(向上,向下,向左,向右)以及CTRL UP和CTRL DWN的功能。我知道这些密钥没有Ascii代码,并且有扫描代码。有人可以帮我找一下扫描码吗?我试过在网上看,但运气不好。如果它与操作系统有关,我在Macintosh上运行Windows 8.1。谢谢!

processKey PROC
    PUSH AX BX
    MOV AH, 10h
    INT 16h
    CMP AL, 1Bh                     ;ESC key?
    JE ESCKey
    JMP F1Key
 ESCKey:
    MOV     AH, 4Ch                
    INT     21h
 F1Key:
    CMP AX, 3B00h                   ;F1 key?
    JE toggleLineType
    JMP F2Key
 toggleLineType:
    CMP singleOrDouble, 0
    JE toggleDouble
    MOV singleOrDouble, 0
    JMP done
 toggleDouble:
    MOV singleOrDouble, 1
    JMP done
 F2Key:
    CMP AX, 3C00h                   ;F2 key?
    JE foregroundToggle
    JMP F3Key
 foregroundToggle:
    CMP foreground, 7
    JE resetForeground
    MOV BL, foreground
    INC BL
    MOV foreground, BL
    JMP done
 resetForeground:
    MOV foreground, 1
 F3Key:
    CMP AX, 3D00h                   ;F3 key?
    JE backgroundToggle
    JMP done
 backgroundToggle:
    CMP background, 7
    JE resetBackground
    MOV BL, background
    INC BL
    MOV background, BL
    JMP done
 resetBackground:
    MOV background, 1
 done:
    POP BX AX
    CALL drawBox
 RET   
processKey ENDP

1 个答案:

答案 0 :(得分:0)

我复制粘贴你的代码并添加了必要的内容以使其与我的EMU8086一起工作(声明了一些变量,空proc draw_box)。首先,我添加了与箭头代码的比较,现在是棘手的部分:在向上和向下箭头(标签arrow_up:,arrow_down :)我们得到键盘标志的状态(ctrl,shift,大写锁定,滚动锁定等) ,如果按下向上箭头并按下Ctrl键,我们有Ctrl +向上(或Ctrl +向下),并跳转到标签ctrl_up:或ctrl_down:。这是代码:

.stack 100h
.data
singleOrDouble DB 0
foreground     DB 0
background     DB 0
.code          
;INITIALIZE DATA SEGMENT.
  mov  ax,@data
  mov  ds,ax

  call processKey

;FINISH THE PROGRAM.
  mov  ax,4c00h
  int  21h           

;--------------------------------------------

processKey PROC
    PUSH AX
    PUSH BX
    MOV AH, 10h
    INT 16h

    cmp ax, 4800h   ;UP.
    je  arrow_up
    cmp ax, 5000h   ;DOWN.
    je  arrow_down
    cmp ax, 4B00h   ;LEFT.
    je  arrow_left
    cmp ax, 4D00h   ;RIGHT.
    je  arrow_right
    cmp ax, 00h
    je  arrow_right
    jmp chkEsc
arrow_up:          
;CHECK IF LEFT CTRL IS PRESSED.
    mov ah, 12h ;GET STATE OF CAPS LOCK, SHIFT, ETC.
    int 21h                                         
    and al, 00000100b ;BITS FOR LEFT CTRL.
    cmp al, 0
    jne ctrl_up
;DO SOMETHING.
    jmp done
ctrl_up:
;DO SOMETHING.
    jmp done
arrow_down:
;CHECK IF LEFT CTRL IS PRESSED.
    mov ah, 12h ;GET STATE OF CAPS LOCK, SHIFT, ETC.
    int 21h                                         
    and al, 00000100b ;BITS FOR LEFT CTRL.
    cmp al, 0
    jne ctrl_down
;DO SOMETHING.
    jmp done
ctrl_down:
;DO SOMETHING.
    jmp done
arrow_left:
;DO SOMETHING.
    jmp done
arrow_right:
;DO SOMETHING.
    jmp done

chkEsc:    
    CMP AL, 1Bh                     ;ESC key?
    JE ESCKey
    JMP F1Key
 ESCKey:
    MOV     AH, 4Ch                
    INT     21h
 F1Key:
    CMP AX, 3B00h                   ;F1 key?
    JE toggleLineType
    JMP F2Key
 toggleLineType:
    CMP singleOrDouble, 0
    JE toggleDouble
    MOV singleOrDouble, 0
    JMP done
 toggleDouble:
    MOV singleOrDouble, 1
    JMP done
 F2Key:
    CMP AX, 3C00h                   ;F2 key?
    JE foregroundToggle
    JMP F3Key
 foregroundToggle:
    CMP foreground, 7
    JE resetForeground
    MOV BL, foreground
    INC BL
    MOV foreground, BL
    JMP done
 resetForeground:
    MOV foreground, 1
 F3Key:
    CMP AX, 3D00h                   ;F3 key?
    JE backgroundToggle
    JMP done
 backgroundToggle:
    CMP background, 7
    JE resetBackground
    MOV BL, background
    INC BL
    MOV background, BL
    JMP done
 resetBackground:
    MOV background, 1
 done:
    POP BX
    POP AX
    CALL drawBox
 RET   
processKey ENDP 

proc drawBox
 RET
endp