What is &H1, &H8000, etc.?

By E.V. Hexworth | Created on 2025-09-02 09:49:32

Written with a enthusiastic tone 🤩 | Model: keyless-mixtral-8x7b

0:00 / 0:00

When programming with Visual Basic (Classic), you might encounter values like &H1 and &H8000. These are hexadecimal numbers that represent specific key codes for keyboard events.

Understanding Hexadecimal

&H represents the number in hexadecimal format, which is a base-16 system. For example:

  • &H1 = 1 (in decimal)
  • &H8000 = 32768 (in decimal)

Example of Use in VB Code

The code snippet provided demonstrates how to use these hexadecimal values to check the state of specific keys:

Public Const VK_SHIFT = &H10
Dim IsShifted As Boolean
IsShifted = (GetKeyState(VK_SHIFT) And &H8000) ' Checks if Shift key is pressed

Explaining &H8000

The value of &H8000 is used to check if a key is down or up. When a key is pressed, the high-order bit (15th bit) of the return value from `GetKeyState` function is set to 1.

  • 1000000000000010 (binary)

Using bitwise AND operation with &H8000 allows you to check if the high-order bit is set:

IsShifted = (GetKeyState(VK_SHIFT) And &H8000) ' If Shift key is down, IsShifted will be True

Checking for ALT Key

To check if the ALT key is pressed, you can use:

Public Const VK_ALT = &H12
Dim IsALT As Boolean
IsALT = (GetKeyState(VK_ALT) And &H8000) ' Checks if ALT key is pressed

Creating a Function to Copy Text to Clipboard

The provided code snippet demonstrates how to create a function that copies text from an input box to the clipboard when both ALT and X keys are pressed simultaneously:

Public Const VK_ALT = &H12
Public Const VK_X = 88 ' ASCII value for 'X'

Public Sub CopyToClipboard()
    Dim IsALT As Boolean
    Dim tempVKCodeHolder As Integer
    
    IsALT = (GetKeyState(VK_ALT) And &H8000) ' Checks if ALT key is pressed
    tempVKCodeHolder = Asc(InputBox("Enter text to copy: ")) ' Gets ASCII value of input
    
    If ((IsALT = True) And (tempVKCodeHolder = VK_X)) Then
        Clipboard.Clear
        Clipboard.SetText "Copied Text"
    End If
End Sub

Conclusion

Understanding hexadecimal values like &H1 and &H8000 is essential for handling keyboard events in Visual Basic (Classic). By using bitwise operations, you can check the state of specific keys to perform actions such as copying text to the clipboard.



Sources:
- [What are &H1, &H8000, etc.? | Tek-Tips] (https://www.tek-tips.com/threads/what-are-h1-h8000-etc.1080522/)
- [Why does font-size not inherit ? | Tek-Tips] (https://www.tek-tips.com/threads/why-does-font-size-not-inherit.1050326/)
- [Microsoft VBScript runtime error '800a01b6' | Tek-Tips] (https://www.tek-tips.com/threads/microsoft-vbscript-runtime-error-800a01b6.419805/)
- [Send 8-bit data over serial port; values over 3F are being set to 3F] (https://www.tek-tips.com/threads/send-8-bit-data-over-serial-port-values-over-3f-are-being-set-to-3f.1672795/)
- [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/)
- [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/)
- [Coverage Paths | Tek-Tips] (https://www.tek-tips.com/threads/coverage-paths.1632312/)
- [Forwarding one internal extension to External number | Tek-Tips] (https://www.tek-tips.com/threads/forwarding-one-internal-extension-to-external-number.1574548/)
- [JOIN from HOLD Files possible? | Tek-Tips] (https://www.tek-tips.com/threads/join-from-hold-files-possible.490981/)
- [SDDPCM query : pcmpath query device | Tek-Tips] (https://www.tek-tips.com/threads/sddpcm-query-pcmpath-query-device-lt-n-gt.1276941/)
Related Posts

No related posts found.