有没有一种方法可以读取基于DOS的Progarmms中的键盘修改键(例如ALT或CTRL)? [英] is there a way to read the Keyboard Modifier Key such as ALT or CTRL in DOS-Based Progarmms?

查看:102
本文介绍了有没有一种方法可以读取基于DOS的Progarmms中的键盘修改键(例如ALT或CTRL)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实知道您可能会轮询键盘缓冲区以获取修饰键,例如ALT或CTRL。但是即使在旧的DOS程序中,当我按下这些键时也有一个动作(例如通过按ALT更改MENU按钮的颜色)。在DOS中是否有办法获取这些密钥?怎么做?我认为在BASIC中将没有解决方案,尽管BASIC有一些可用的ON Eventhandler。欢迎对此问题提出任何建议或建议。

I do know that you might polling the keyboard buffer to get the Modifier Keys such as ALT or CTRL. But even in old DOS Programms there was an Action when I just pressed these keys (f.e. to change the Color of the MENU buttons by pressing ALT). Is there a way in DOS to get these Keys? How is this be done? I think in BASIC there would be no solution although BASIC has some ON Eventhandler available. Any recommands or advices to this questions are welcome.

推荐答案

您可以在线性状态下查看 KeyboardStatusFlags BIOS数据区域中的地址1047。对于 Alt 键,您检查第3位,对于 Ctrl 键,您检查第2位。下一个QBASIC程序正是这样做的:

You can look at the KeyboardStatusFlags at linear address 1047 in the BIOS data area. For the Alt key you examine bit 3, and for the Ctrl key you examine bit 2. Next QBASIC program does exactly that:

DEF SEG = 0
DO
  IF PEEK(1047) AND 8 THEN
    PRINT "ALT is pressed"
    EXIT DO
  ELSEIF PEEK(1047) AND 4 THEN
    PRINT "CTRL is pressed"
    EXIT DO
  END IF
LOOP


注释



还有一种方法可以通过窥视地址来获得按键(ASCII值)?

Is there also a way to get the KEY Pressed (ASCII VALUE) by peeking an address?

同样,您可以在键盘缓冲区(循环缓冲区)中找到此信息。 BIOS维护一个字长的指针,该指针指向存储下一个可用密钥的位置(HEAD),而字长大小的指针指向在其后存储最近缓冲的密钥的位置(TAIL)。如果HEAD等于TAIL,则键盘缓冲区为空。 INKEY $ 在这种情况下将返回一个空字符串。

Again you can find this info in the keyboard buffer (a circular buffer). BIOS maintains a word-sized pointer to the place where the next available key is stored (HEAD), and a word-sized pointer to the place behind where the most recently buffered key is stored (TAIL). If HEAD equals TAIL, then the keyboard buffer is empty. INKEY$ would return an empty string in this case.

Head% = PEEK(1050) + 256 * PEEK(1051)
Tail% = PEEK(1052) + 256 * PEEK(1053)
IF Head% <> Tail% THEN
  Ascii% = PEEK(1024 + Head%)
  Scan% = PEEK(1024 + Head% + 1)
ELSE
  Ascii% = 0
  Scan% = 0
END IF

以上代码的优势是您可以预览键盘缓冲区中的下一个可用键(如果有)。密钥不会被删除。 INKEY $ 可以提供相同的信息,但也会删除该密钥

The 'advantage' of above code is that you can preview what key (if any) is available next in the keyboard buffer. The key is not removed. INKEY$ can give the same info but will remove the key also.

这篇关于有没有一种方法可以读取基于DOS的Progarmms中的键盘修改键(例如ALT或CTRL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆