468,268 Members | 1,977 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,268 developers. It's quick & easy.

Keys.Oem1 etc to real character

Hi,

How can I convert KeyCode's to the real character? For instance: the row of
keys on a keyboard under the F-keys return as Keycode the Keys.Oem1,
Keys.Oem2 etc... Depending on the keyboard layout it is another character
(and also depening on the fact if you have used Shift or Alt Gr).

But my problem is: I would like to knwo the exact character the user sees on
the screen.

I'm using VB.NET 2003.

Thanks a lot in advance,

Pieter
Dec 14 '06 #1
5 1474
Ummmmmmmm ... How about Convert.ToChar(Keys.Oem1)
"Pieter" <pi****************@hotmail.comwrote in message
news:Ol*************@TK2MSFTNGP06.phx.gbl...
Hi,

How can I convert KeyCode's to the real character? For instance: the row
of keys on a keyboard under the F-keys return as Keycode the Keys.Oem1,
Keys.Oem2 etc... Depending on the keyboard layout it is another character
(and also depening on the fact if you have used Shift or Alt Gr).

But my problem is: I would like to knwo the exact character the user sees
on the screen.

I'm using VB.NET 2003.

Thanks a lot in advance,

Pieter

Dec 14 '06 #2
or even Asc(Keys.Oem1)
Dec 14 '06 #3
No. Asc(Keys.Oem1) will return a byte. You need AscW(Keys.Oem1) to return
a char.
"Stuart Nathan" <st***********@homecall.co.ukwrote in message
news:u9**************@TK2MSFTNGP06.phx.gbl...
or even Asc(Keys.Oem1)

Dec 14 '06 #4
Hi,

I tried these alreaddy, but they don't work...
For instance:
The 2 upper left keys on my keyboard (under the Esc-key) are (I'm using an
Belgian Azerty): "" and "&".

What I get for them is:
"":
- KeyCode = 222 = Keys.OemQuotes
- Convert.ToChar(e.KeyCode) = ""c (I don't even knwo the name of this sign,
I hope it shows up in the newsreader...)
- Asc(e.KeyCode) = AscW(e.KeyCode) = 50

"&":
- KeyCode = 49 = Keys.D1
- Convert.ToChar(e.KeyCode) = "1"c (If I do Shift + ThisKey then I get
indeed "1", but I did it without the Shift...)
- Asc(e.KeyCode) = AscW(e.KeyCode) = 52
Anybody has any idea??? I'm really stuck on this :-(


"Stephany Young" <noone@localhostwrote in message
news:uK**************@TK2MSFTNGP02.phx.gbl...
No. Asc(Keys.Oem1) will return a byte. You need AscW(Keys.Oem1) to
return a char.
"Stuart Nathan" <st***********@homecall.co.ukwrote in message
news:u9**************@TK2MSFTNGP06.phx.gbl...
>or even Asc(Keys.Oem1)


Dec 14 '06 #5
Aaah, I found it :-)

Declare Function ToAscii Lib "user32" (ByVal uVirtKey As Integer, ByVal
uScanCode As Integer, ByRef lpbKeyState As Byte, ByRef lpwTransKey As
Integer, ByVal fuState As Integer) As Integer
Private Declare Function GetKeyboardState Lib "user32.dll" (ByRef
pbKeyState As Byte) As Long

Private Function GetCharFromKey(ByVal KeyCode As Integer) As String
Dim KeyBoardState(255) As Byte
Dim Out As Long
If GetKeyboardState(KeyBoardState(0)) <0 Then
If ToAscii(KeyCode, 0, KeyBoardState(0), Out, 0) <0 Then
If Out <= 255 Then
GetCharFromKey = Chr(Out)
Else
'GetCharFromKey =
Microsoft.VisualBasic.Left(StrConv(ChrW(Out), vbUnicode), 1)
GetCharFromKey =
Microsoft.VisualBasic.Left(StrConv(ChrW(Out), VbStrConv.None), 1)
End If
Else
GetCharFromKey = ""
End If
Else
GetCharFromKey = ""
End If
End Function


Dec 14 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Andrew DeFaria | last post: by
2 posts views Thread by paytam | last post: by
90 posts views Thread by Christoph Zwerschke | last post: by
4 posts views Thread by Broeisi | last post: by
5 posts views Thread by Pieter | last post: by
2 posts views Thread by John | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.