Unveiling the Mystery of &H1, &H8000, and More

By Roderick Wystan Codegraveer | Created on 2025-07-22 18:55:29

Written with a analytical tone 🧠 | Model: benevolentjoker/nsfwvanessa:latest

0:00 / 0:00
In programming, particularly in Visual Basic (Classic), hexadecimal numbers preceded by an ampersand (&) are often used to represent various constants. In this thread on Tek-Tips, we'll explore the meaning behind these mysterious symbols and how they're used in code.

What does &H mean?

Before diving into the specifics, let's clarify what the &H prefix represents. It simply means that the number is written in hexadecimal (base 16) format. For example, &H1 is equivalent to decimal 1, while &H8000 represents decimal 32768.

GetKeyState and bitwise AND

When working with keyboard input, the GetKeyState function plays a crucial role in determining the state of a key. The return value of this function is a 16-bit integer (a SHORT data type in Visual Basic), which can be thought of as two separate bytes. The high-order bit (the most significant bit) indicates whether the key is down (1) or up (0). The low-order bit, on the other hand, is used to indicate if the key is toggled. When using bitwise AND (&) with the GetKeyState return value and a hexadecimal constant like &H8000, it's essential to understand that this operation sets the high-order bit of the result. In the case of the Shift key, its virtual key code is &H10 (binary: 0000000000000010). When the Shift key is down, GetKeyState returns a value like 1000000000000010. By using bitwise AND with &H8000 (binary: 1000000000000000), you effectively set the high-order bit of the result to indicate that the Shift key is down.

Checking for specific keys

To check whether a specific key, such as the ALT key, has been pressed, you can use its virtual key code (&H12) and apply the same bitwise AND approach. For example, if you want to detect when the user presses ALT + X, you would first declare a constant for the ALT key: ```vb Public Const VK_ALT = &H12 ``` Then, in your code, you can use GetKeyState with.VK_ALT and check the result using bitwise AND with &H8000: ```vb IsALT = (GetKeyState(VK_ALT) And &H8000) ``` By combining this logic with a conditional statement, you can trigger specific actions based on the state of the ALT key.

Conclusion

In summary, the mysterious &H numbers in Visual Basic represent hexadecimal constants that are used to identify various keys and states. By understanding how GetKeyState works and applying bitwise AND operations, you can effectively detect and respond to keyboard input events in your code. Whether you're building a text editor, a game, or any other application that interacts with the user's input, this knowledge will help you create more robust and responsive programs.

Sources:
- [What are &H1, &H8000, etc.? | Tek-Tips] (https://www.tek-tips.com/threads/what-are-h1-h8000-etc.1080522/)
- [stop h1 tag going onto next line | Tek-Tips] (https://www.tek-tips.com/threads/stop-h1-tag-going-onto-next-line.876965/)
- [Microsoft VBScript runtime error '800a01b6' | Tek-Tips] (https://www.tek-tips.com/threads/microsoft-vbscript-runtime-error-800a01b6.419805/)
- [Why does font-size not inherit ? | Tek-Tips] (https://www.tek-tips.com/threads/why-does-font-size-not-inherit.1050326/)
- [Launch .VBS file from button on HTML page | Tek-Tips] (https://www.tek-tips.com/threads/launch-vbs-file-from-button-on-html-page.931380/)
- [center-align menu item text | Tek-Tips] (https://www.tek-tips.com/threads/center-align-menu-item-text.1769404/)
- [Moving Aplications to a new screen in C# | Tek-Tips] (https://www.tek-tips.com/threads/moving-aplications-to-a-new-screen-in-c.1416749/)
- [Error: Only content controls are allowed directly in a ... - Tek-Tips] (https://www.tek-tips.com/threads/error-only-content-controls-are-allowed-directly-in-a-content-page.1504551/)
- [SDDPCM query : pcmpath query device | Tek-Tips] (https://www.tek-tips.com/threads/sddpcm-query-pcmpath-query-device-lt-n-gt.1276941/)
- [how do i keep sections from moving when i minimize window?] (https://www.tek-tips.com/threads/how-do-i-keep-sections-from-moving-when-i-minimize-window.1611893/)