Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What are &H1, &H8000, etc.?

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
Hi, I'm just wondering if anyone could tell me what &H1 is, or what &H8000 means, etc?

Code:
Public Const VK_SHIFT = &H10
Public Const VK_CAPITAL = &H14
Public Const VK_CONTROL = &H11

Dim IsShifted As Boolean
Dim IsCaps As Boolean
Dim IsCtrl As Boolean

IsCaps = (GetKeyState(VK_CAPITAL) And &H1) 'Caps
IsShifted = (GetKeyState(VK_SHIFT) And &H8000) 'Shift Key
IsCtrl = (GetKeyState(VK_CONTROL) And &H8000) 'Ctrl Key


-Ovatvvon :-Q
 
&H means the number is hexadecimal (ie base 16)

&H1 = decimal 1
&H8000 = decimal 32768

u can use the windows calculator to swap between diffent bases to try these out for yourself

If somethings hard to do, its not worth doing - Homer Simpson
 
Hmm, so I'm confused then. For the case of the "IsShifted" variable: Would something like that be detecting if the KeyCode value for shift (&H10) has been entered, and adds the value of &H8000 to it? Or, what's the purpose of &H8000?

-Ovatvvon :-Q
 
Did you look at the MSDN page for the GetKeyState function?

Here is the link:
I think the answer you seek can be found in this part:
Code:
[b]Return Value[/b]

The return value specifies the status of the specified virtual key, as follows: 

If the high-order bit is 1, the key is down; otherwise, it is up.

If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.
 
So the GetKeyState return value is data type SHORT... So it is a 16 bit number... just like a VB INT.

I will do the rest in a code box so it uses the courier font so everything lines up...
Code:
In binary VK_SHIFT (&H10) would be:       0000000000000010
So if Shift is down, GetKeyState returns: 1000000000000010
In binary &H8000 lights up the top bit:   1000000000000000

So use bitwise AND to test like this... 
     1000000000000010
 AND 1000000000000000
---------------------
   = 1000000000000000
 
So if I want to check whether the ALT key has been pressed or not, am I correct in believing that it is of value &H12 and it should be assigned the &H8000?

So if I wanted to make a function, for instance, that copied the text from an inputbox to the clipboard when the user selected ALT and X, I would type the following (minus a few lines declaring functions and such to save space and time)???

Code:
Public Const VK_ALT = &H12
Public Type KBDLLHOOKSTRUCT
    vkCode As Long ' virtual keycode
    scanCode As Long ' hardware scancode
    flags As Long
    time As Long
    dwExtraInfo As Long
End Type

Dim IsALT As Boolean

IsALT = (GetKeyState(VK_ALT) And &H8000) 'Ctrl Key
tempVKCodeHolder = correctedInputValues(CInt(Trim(HookStruct.vkCode))) 'Takes the interpreted keyboard input value and translates it to it's proper ascii value.

If ((IsAlt = True) And (tempVKCodeHolder = 88)) Then
  'If ALT and "X" are pressed at the same time,
  'the user's data Copied to the Clipboard.

  Clipboard.Clear
  Clipboard.SetText (strUserInput)
  Exit Function
End If


-Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top