473,397 Members | 2,084 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,397 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 1630
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.