From: David De Bono on
Hi!

Using GetKeyboardState makes it very complicated since I need to know the
keyboard layout of every language, and then convert it. This is a task for
the operating system. That's why I'm asking for a better solution.

This should be very simple actually. Just a API call for example to get the
correct Unicode of the key pressed with the user chosen keyboard.

This is actually what the KeyPress event should have done supporting
Unicode.

For example:

Private Sub Form_KeyPress(KeyAscii As Integer)

label1.caption=chrw(keyascii)

"Karl E. Peterson" <karl(a)exmvps.org> skrev i nyhetsmeldingen:
i2a5ci$25h$1(a)news.eternal-september.org ...
> David De Bono used his keyboard to write :
>> Have not looked so much into ToUnicode yet, but in order to use that I
>> first need a the virtual keycode for the key pressed.
>>
>> The keydown event does not work because it only returns a 8 bit code.
>
> But it provides a trigger for a call to GetKeyboardState? Of course, you
> could simply subclass the window(s) you're interested in, and monitor
> input directly.
>
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
>
>
From: David De Bono on
I found the solution using PeekMessageW

"David De Bono" <er_fortsatt(a)hotmail.com> skrev i nyhetsmeldingen:
5A61A370-3FFF-42C3-84B2-DFC7B0F67397(a)microsoft.com ...
> Hi!
>
> Using GetKeyboardState makes it very complicated since I need to know the
> keyboard layout of every language, and then convert it. This is a task for
> the operating system. That's why I'm asking for a better solution.
>
> This should be very simple actually. Just a API call for example to get
> the correct Unicode of the key pressed with the user chosen keyboard.
>
> This is actually what the KeyPress event should have done supporting
> Unicode.
>
> For example:
>
> Private Sub Form_KeyPress(KeyAscii As Integer)
>
> label1.caption=chrw(keyascii)
>
> "Karl E. Peterson" <karl(a)exmvps.org> skrev i nyhetsmeldingen:
> i2a5ci$25h$1(a)news.eternal-september.org ...
>> David De Bono used his keyboard to write :
>>> Have not looked so much into ToUnicode yet, but in order to use that I
>>> first need a the virtual keycode for the key pressed.
>>>
>>> The keydown event does not work because it only returns a 8 bit code.
>>
>> But it provides a trigger for a call to GetKeyboardState? Of course, you
>> could simply subclass the window(s) you're interested in, and monitor
>> input directly.
>>
>> --
>> .NET: It's About Trust!
>> http://vfred.mvps.org
>>
>>
From: Karl E. Peterson on
It happens that David De Bono formulated :
> I found the solution using PeekMessageW

Curious, care to share?

>> This should be very simple actually. Just a API call for example to get the
>> correct Unicode of the key pressed with the user chosen keyboard.

Agreed.

>> This is actually what the KeyPress event should have done supporting
>> Unicode.
>>
>> For example:
>>
>> Private Sub Form_KeyPress(KeyAscii As Integer)
>>
>> label1.caption=chrw(keyascii)

Yep, Microsoft *totally* botched the switch to Unicode, in nearly every
possible way.

--
..NET: It's About Trust!
http://vfred.mvps.org


From: David De Bono on
Here:

Public Declare Function PeekMessageW Lib "user32" (lpMsg As msg, ByVal hWnd
As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal
wRemoveMsg As Long) As Long

Public Const WM_KEYFIRST = &H100
Public Const WM_KEYLAST = &H108

Public Type POINTAPI
x As Long
y As Long
End Type

Public Type msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type

Public Function GetLastKeyPressed() As Long

Dim Message As msg

If PeekMessageW(Message, 0, WM_KEYFIRST, WM_KEYLAST, 0) Then
GetLastKeyPressed = Message.wParam
Else
GetLastKeyPressed = -1
End If

Exit Function

End Function


"Karl E. Peterson" <karl(a)exmvps.org> skrev i nyhetsmeldingen:
i2cdq3$ov$1(a)news.eternal-september.org ...
> It happens that David De Bono formulated :
>> I found the solution using PeekMessageW
>
> Curious, care to share?
>
>>> This should be very simple actually. Just a API call for example to get
>>> the correct Unicode of the key pressed with the user chosen keyboard.
>
> Agreed.
>
>>> This is actually what the KeyPress event should have done supporting
>>> Unicode.
>>>
>>> For example:
>>>
>>> Private Sub Form_KeyPress(KeyAscii As Integer)
>>>
>>> label1.caption=chrw(keyascii)
>
> Yep, Microsoft *totally* botched the switch to Unicode, in nearly every
> possible way.
>
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
>
>
From: Karl E. Peterson on
David De Bono has brought this to us :
>>> I found the solution using PeekMessageW
>>
>> Curious, care to share?
>
> Here:
>
> Public Declare Function PeekMessageW Lib "user32" (lpMsg As msg, ByVal hWnd
> As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal
> wRemoveMsg As Long) As Long
>
> Public Const WM_KEYFIRST = &H100
> Public Const WM_KEYLAST = &H108
>
> Public Type POINTAPI
> x As Long
> y As Long
> End Type
>
> Public Type msg
> hWnd As Long
> Message As Long
> wParam As Long
> lParam As Long
> time As Long
> pt As POINTAPI
> End Type
>
> Public Function GetLastKeyPressed() As Long
>
> Dim Message As msg
>
> If PeekMessageW(Message, 0, WM_KEYFIRST, WM_KEYLAST, 0) Then
> GetLastKeyPressed = Message.wParam
> Else
> GetLastKeyPressed = -1
> End If
>
> Exit Function
>
> End Function

Called from *_KeyDown? Nice. It's only seeming to miss the navigation
and state keys?

--
..NET: It's About Trust!
http://vfred.mvps.org