473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 7612
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Robert Brown | last post by:
Let's say I have a type hierarchy: (just an example) the general entity customer: CREATE TABLE customer(customer_id int, customer_name varchar(250), customer_type int) three specific...
4
by: Andrew DeFaria | last post by:
I'm trying to use the onKeyDown event on a text field. I intersept the keystroke, interpret it and then do certain actions based on certain keys stuck. If a special key is stuck I replace the value...
6
by: Brendan Jurd | last post by:
Hi all, I read on the manual page for Inheritance that: "A limitation of the inheritance feature is that indexes (including unique constraints) and foreign key constraints only apply to single...
2
by: paytam | last post by:
Hi all I want to use combine keys in my code such as ctrl+w or or Alt or F keys.What should I do? and is there any special data type which I use for this purpose?
90
by: Christoph Zwerschke | last post by:
Ok, the answer is easy: For historical reasons - built-in sets exist only since Python 2.4. Anyway, I was thinking about whether it would be possible and desirable to change the old behavior in...
4
by: Broeisi | last post by:
Hello, I'm trying to write a console based program in C in Linux. I want to use the function keys in my program, but I don;t know how to let the C program know when for exmaple the F1 key is...
9
by: Laphan | last post by:
Hi All I'm using the below to limit the input into a text box to just letters, numbers, hyphens and full stops, but I also need to allow the backspace, delete and arrow keys to come through. ...
5
by: Pieter | last post by:
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...
4
by: Mo | last post by:
Hi, I am writing a console application to send a key sequence to an old clunky application on a regular interval using the windows scheduler. I can get it to work if it is a windows form...
2
by: John | last post by:
where are the following key codes in System.Windows.Forms.Keys : ; * = . , ' " thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.