News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ASCII code for Ctrl+F == Backspace?

Started by omdown, June 02, 2005, 01:25:22 AM

Previous topic - Next topic

omdown

Weird problem guys . . .

I'm working on something that's supposed to respond to Ctrl+F, seems simple enough, I just told it to respond to the ASCII code for Ctrl+F (06h), which worked great, until I discovered that whenever I pressed backspace, it for some reason responded like I pressed Ctrl+F.  I'm a little confused as to why this is happening.  Can anyone help me understand why this is happening?


MichaelW

Is this for a Windows Console app, or a DOS app?
eschew obfuscation

MichaelW

I'm going to assume this is for a Windows Console app.

There is no ASCII code for Ctrl+F. The PC BIOS Extended Keyboard Functions will return scan code 21h and character code 06h for this key combination. The 21h is the actual scan code for the 'F' key, and I think the 06h was the result of clearing certain bits in the actual ASCII code 66h. ASCII code 06h is defined as the control character ack(nowledge).

For a Windows Console app I think you should detect the key combination by checking the keys individually. I don't know if the high-level input functions will allow you to do this, but the ReadConsoleInput function will. The function will return an event of type KEY_EVENT for each key press and release, and a KEY_EVENT_RECORD structure that specifies the virtual key code (VK_F in this case) and the control key state ("control key" here meaning any of the shift/toggle keys). For a Ctrl+F combination the control key state would be LEFT_CTRL_PRESSED OR RIGHT_CTRL_PRESSED.

MSDN: Character Mode Applications
eschew obfuscation

tenkey

Backspace is control-H.
Does control-H do something similar to control-F?
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

MichaelW

tenkey,

I didn't notice before, but the code here:

http://www.masmforum.com/simple/index.php?topic=1818.0

That I think is the actual subject of this thread, defines:

CTRL_F = 06h
CTRL_E = 05h
CTRL_H = 08h


In its current form the code does not actually use CTRL_H, but the code that checks the keys uses Interrupt 21h, Function 1, which returns only the character code, so Backspace and Ctrl+H would both return 8. Perhaps omdown was just confusing Ctrl+F and Ctrl+H.

omdown,

If I am correct about this, you can fix two problems by using the BIOS keyboard functions (Interrupt 16h, Functions 0, 1, 10h, 11h) to read the keys. Unlike the DOS function, the BIOS functions will not echo the character, and the returned AX value (scan code in AH, character code in AL) can be used to uniquely identify the key combinations (Ctrl+E = 1205h, Ctrl+F = 2106h, Ctrl+H = 2308h).
eschew obfuscation

vitsoft

When I was confused with Backspace versus ^H and the differences between left-Ctrl^H and right-Ctrl^H ten years ago, I wrote a simple monitoring tool OPIN Key.