首页 > 解决方案 > 有没有办法在汇编中将键盘重复延迟设置为零?

问题描述

我正在制作一个汇编程序,根据按下的键在屏幕上移动一个像素。

根据这里修改重复延迟的方法是使用

mov ah, 03h 
mov al, 05h ;set typematic rate/delay
mov bh, 00h ;repeat delay: 250ms <-- this has to be 0
mov bl, 00h ;typematic rate: 30
int 16h

这是整个代码

cmp [keypress], 'a'
je left
cmp [keypress], 'A'
je left
cmp [keypress], 'd'
je right
cmp [keypress], 'D'
je right
jmp endMove
left:
    dec xpos
    jmp endMove
right:
    inc xpos
    jmp endMove
endMove:
call drawPixel
input:
mov keypress, 0
mov ah, 01h
int 16h
jnz animLoop
mov ah, 00h
int 16h
mov keypress, al
jmp animLoop

它工作正常,除了键盘重复延迟使像素移动一次,然后停止 250 毫秒,然后重新开始连续移动而没有问题。如何消除重复延迟?

标签: assemblyinputkeyboarddosx86-16

解决方案


可以在 BIOS 选项中配置此延迟(以及重复率)。如果要绕过它,则不应使用 BIOS 功能,而应直接访问键盘控制器

在您的代码中

mov bh, 00h ;repeat delay: 250ms <-- this has to be 0

尝试设置重复延迟的值,该值0代表 250 毫秒,可以在 BIOS 中/通过 BIOS 中断设置的最小值。您可以在Ralph Brown 的中断列表上验证这一点。


推荐阅读