From: Boris Pauljev on
Something is wrong...

' Get the keyboard scan code for "T":
Dim b() As Byte
b = sChar 'sChar is "T"
CopyMemory vKey, b(0), 2 'vKey becomes "84"

Dim iKeyCode%
iKeyCode = VkKeyScanW(vKey) 'For "T", iKeyCode becomes "340"

' Split into shift and key portions:
iShift = (iKeyCode And &HFF00&) \ &H100& 'iShift becomes "1"
vKey = iKeyCode And &HFF& 'vKey stays "84"

Const VKSHIFT = &H100
Const VKCTRL = &H200
Const VKALT = &H400

Dim bShift As Boolean
Dim bAltGr As Boolean
Dim bCtrl As Boolean

bShift = CBool(iShift And VKSHIFT) '1 AND 256 = FALSE
bCtrl = CBool(iShift And VKCTRL) '1 AND 512 = FALSE
bAltGr = CBool(iShift And VKALT) '1 AND 1024 = FALSE

This means that for "T" is says that no shift is being used.
From: Bob Butler on

"Boris Pauljev" <nordiccoder(a)hotmail.com> wrote in message
news:e1kS7y75KHA.1888(a)TK2MSFTNGP05.phx.gbl...
> Something is wrong...
>
> ' Get the keyboard scan code for "T":
> Dim b() As Byte
> b = sChar 'sChar is "T"
> CopyMemory vKey, b(0), 2 'vKey becomes "84"
>
> Dim iKeyCode%
> iKeyCode = VkKeyScanW(vKey) 'For "T", iKeyCode becomes "340"
>
> ' Split into shift and key portions:
> iShift = (iKeyCode And &HFF00&) \ &H100& 'iShift becomes "1"
> vKey = iKeyCode And &HFF& 'vKey stays "84"
>
> Const VKSHIFT = &H100
> Const VKCTRL = &H200
> Const VKALT = &H400
>
> Dim bShift As Boolean
> Dim bAltGr As Boolean
> Dim bCtrl As Boolean
>
> bShift = CBool(iShift And VKSHIFT) '1 AND 256 = FALSE
> bCtrl = CBool(iShift And VKCTRL) '1 AND 512 = FALSE
> bAltGr = CBool(iShift And VKALT) '1 AND 1024 = FALSE

Sorry, I didn't copy & paste right.... the point was to avoid the bit
shifting and just use the return value from vkkeyscan

bShift = CBool(iKeyCode And VKSHIFT) '1 AND 256 = FALSE
bCtrl = CBool(iKeyCode And VKCTRL) '1 AND 512 = FALSE
bAltGr = CBool(iKeyCode And VKALT) '1 AND 1024 = FALSE


From: Bob Butler on

"Jeff Johnson" <i.get(a)enough.spam> wrote in message
news:eiZiFS75KHA.4116(a)TK2MSFTNGP02.phx.gbl...
> "Bob Butler" <noway(a)nospam.ever> wrote in message
> news:OmYPjG75KHA.3292(a)TK2MSFTNGP06.phx.gbl...
>
>> bAltGr =cbool(iShift And vkAlt)
>
> Just to split hairs on your naming, you don't really know it's AltGr as
> opposed to just Alt.

I named them based on the values defined in the docs for vkkeyscan; I don't
remember offhand how to differentiate between alt and altgr. I know I've
looked into it before but that was a long time ago.

From: Bob Butler on

"Boris Pauljev" <nordiccoder(a)hotmail.com> wrote in message
news:O3uDFX75KHA.5548(a)TK2MSFTNGP04.phx.gbl...
> Bob, I am not sure yet, but I think your code works.... OMG, I would
> really be up in the sky if this really works. I will test it on a client
> computer now (who has not yet given up yet... luckily..)
>
> Can you explain why vbAltMask is not what I want? I mean what is it good
> for if one cannot use it anyway?

It's useful when you are dealing with the values in the KeyDown & KeyUp
events; they are vb constants and vkkeyscan is not a VB function so there's
not necessarily going to be any relationship between what it returns and
what vb uses in other places.


From: Boris Pauljev on
Thanks, but when I have

vKey = 105
iKeyCode = 1605

it still tells me that Alt and Ctrl are pressed.

iKeyCode comes from

iKeyCode = VkKeyScanW(vKey)

When the shift and alt and ctrl detecting seems to be correct, then
VkKeyScanW appears to be the bad boy, right? Or does anybody disagree?
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6
Prev: GetAttr under Vista and Win 7
Next: Mystery 3 Surfaces Again