如何等到 NASM 中指定的键被按下?

How to wait until specified keys will be pressed in NASM?

我正在创建自定义 MBR,它将加载我的消息,在我按下指定的键后 CTRL+ALT+ESC 它将加载原始 MBR,除了等待键外,我已完成所有操作。我找到了等待 any 按键的代码,但我已经指定了键,我知道我可以使用 AL 来设置按钮的 ASCII 字符按下,但我有 3 个组合键,而且它们不是 ASCII 字符。那么我该如何实现呢?

这是我的部分代码,这只是示例:

org 0x7c00
bits 16

    ; wait for key
    mov ah,0
    int 16h

    ; reboot
    int 19h


MBR_signature:
times 510-($-$$) db 0 
db 55h,0aah

您可以使用 Int 16/AH=00h to wait for the next keystroke. You can continue checking for keystrokes until ESCAPE is pressed. The scan code for ESCAPE is 01h. If it has been pressed then you can use Int 16/AH=02h 来获取移位标志,其中包括 CONTROL and/or ALT 当前是否处于按下。 AL 的第 2 位和第 3 位将包含它们的当前状态。此代码段应演示 CONTROLALT ESCAPE:

的检测
org 0x7c00
bits 16

getkey:
    xor ah,ah          ; AH = 0
    int 16h            ; Wait for key
    cmp ah, 01h        ; Scan code 1 = Escape
    jne getkey         ; If Escape not pressed get another key

    mov ah,2h
    int 16h            ; Query keyboard status flags
    and al, 0b00001111 ; Mask all the key press flags
    cmp al, 0b00001100 ; Check if ONLY Control and Alt are pressed and make sure
                       ;    Left and/or Right Shift are not being pressed
    jne getkey         ; If not go back and wait for another keystroke
                       ;    Otherwise Control-Alt-Escape has been pressed
    ; reboot
    int 19h

MBR_signature:
times 510-($-$$) db 0
db 55h,0aah