How Do Keyboard Scan Codes Work with Modified Keys like 'Alt' or 'Ctrl'?

In summary, the conversation discusses the use of Pascal programs to catch keyboard scan codes, specifically for keys modified with "Alt" or "Ctrl". The speaker is curious about how to check for these modified keys in the keyboard buffer and whether a key combination like "Alt-F4" would be interpreted as a single scan code or multiple keypresses. A helpful resource for understanding keyboard scan codes is also mentioned.
  • #1
aychamo
375
0
Hey guys;

I was driving the other night, and I was thinking about some programs I used to write many years ago in Pascal (like ~ 11-12 years ago in TurboPascal 7.0, or was it 6.0?) in which I used to catch the keyboard scan codes.

I realized that I neve caught a keyboard scan code for a key that was modified with "Alt" or "Ctrl". I remember for an arrow key you would check for (0 + 75) or something. How would you check the keyboard "buffer" for presence of a key which is modified with Alt or Ctrl?

Also, would, say, "Alt-F4" be a single keyboard scan code, or would the keyboard interpret it as mulitple keypresses?

I'm just curious :)
 
Computer science news on Phys.org
  • #3


Hi there,

That's a great question! Keyboard scan codes can definitely be tricky to work with, especially when it comes to modified keys like "Alt" or "Ctrl". The reason you may not have caught a keyboard scan code for a modified key is because these keys are not considered as separate keys by the operating system. Instead, they are modifiers that change the behavior of other keys when pressed in combination.

To check for the presence of a key modified with "Alt" or "Ctrl", you would need to use a different approach. One way to do this would be to use the GetAsyncKeyState function in Windows, which allows you to check the state of a specific key at any given time. This function returns a bit flag indicating whether the key is currently pressed or not, and you can use this to determine if a modified key is being pressed along with another key.

As for your second question, "Alt-F4" would not be a single keyboard scan code. It would be interpreted as two separate keypresses - "Alt" and "F4". This is because the "Alt" key is a modifier and does not have its own scan code. It simply modifies the behavior of the "F4" key, which would have its own scan code.

I hope this helps answer your questions and satisfy your curiosity! Let me know if you have any further questions or need clarification on anything. Happy coding!
 

1. What is a keyboard scan code?

A keyboard scan code is a unique code that is sent by a keyboard to a computer when a key is pressed. It identifies which key has been pressed and is used by the computer to generate the appropriate character or action.

2. How are keyboard scan codes used?

Keyboard scan codes are used by the computer's operating system to interpret and process keyboard input. They are also used by software applications to determine which keys have been pressed.

3. Are keyboard scan codes the same for all keyboards?

No, keyboard scan codes can vary depending on the type and brand of keyboard. Different manufacturers may use different codes for the same key.

4. Can keyboard scan codes be modified or customized?

Yes, some keyboards allow for customization of the scan codes for certain keys. This can be useful for gaming or programming purposes.

5. How do I find the keyboard scan code for a specific key?

You can use a keyboard testing software or program to display the scan codes for each key as you press them. You can also refer to the keyboard's manual or contact the manufacturer for more information.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
Back
Top