PC Review


Reply
Thread Tools Rate Thread

ASCII Keyboard Code for VB.Net

 
 
Lumpierbritches
Guest
Posts: n/a
 
      2nd Mar 2004
Thank you in advance for any and all assistance. Is there a way in VB.Net to
call the ASCII equivilalent to each corresponding keypress?

Similar to VB6, using KeyAscii?

If KeyAscii <= 26 Then Exit Sub
Dim I As Integer

I was able to pull ASCII codes for each letter or keypress, which this code
above. Is there a way to do this in DotNet?

Michael
 
Reply With Quote
 
 
 
 
Scott
Guest
Posts: n/a
 
      2nd Mar 2004
The KeyPress event in .NET has a KeyPressEventArgs object which contains a
member named KeyChar. This member contains the ASCII character code. You can
use this in several ways....

Sub keypressed(ByVal o As [Object], ByVal e As KeyPressEventArgs)
' Using the character code
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
e.Handled = True
End If
' Using the Keys enumeration
If e.KeyChar = Keys.Enter Then
e.Handled = True
End If
End Sub 'keypressed


"Lumpierbritches" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thank you in advance for any and all assistance. Is there a way in VB.Net

to
> call the ASCII equivilalent to each corresponding keypress?
>
> Similar to VB6, using KeyAscii?
>
> If KeyAscii <= 26 Then Exit Sub
> Dim I As Integer
>
> I was able to pull ASCII codes for each letter or keypress, which this

code
> above. Is there a way to do this in DotNet?
>
> Michael



 
Reply With Quote
 
Lumpierbritches
Guest
Posts: n/a
 
      2nd Mar 2004
Thank you, however I'm sure I was unclear. I want to pull and place into a
lblName.text the ASCII equivalent to the Key Pressed on the keyboard. I'm using
this for a psuedo registration/password algo. for a small program. Each time a
key is pressed on the keyboard, the lblName.Text will reflect the keypress
equivalent to the corresponding ASCII numeric value.

Michael
 
Reply With Quote
 
Scott
Guest
Posts: n/a
 
      2nd Mar 2004
I'm still not quite sure I understand what you're looking for. If you want
to capture a system-wide key press (not only from within a certain form or
application) then I suggest checking out the following article on low-level
keyboard hooks in VB.NET
(http://www.developer.com/net/net/art...1087_2193301_1). If you are
trying to catch key press events from a specific textbox in your application
then use the KeyPressEventArgs object as I suggested previously...

Sub keypressed(ByVal o As [Object], ByVal e As KeyPressEventArgs)
lblName.Text += e.KeyChar.ToString()
End Sub

KeyChar is of type "Char" which means you can do anything with it that you
can do with a "Char" object including getting the ASCII code or character...


"Lumpierbritches" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thank you, however I'm sure I was unclear. I want to pull and place into a
> lblName.text the ASCII equivalent to the Key Pressed on the keyboard. I'm

using
> this for a psuedo registration/password algo. for a small program. Each

time a
> key is pressed on the keyboard, the lblName.Text will reflect the keypress
> equivalent to the corresponding ASCII numeric value.
>
> Michael



 
Reply With Quote
 
Michael Hesse
Guest
Posts: n/a
 
      3rd Mar 2004
If I enter the code
If e.KeyChar = Keys.Enter Then ...
I get this error message:

Operator '=' is not defined for types 'Char' and
'System.Windows.Forms.Keys'.

Am I doing something wrong?

Michael

"Scott" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The KeyPress event in .NET has a KeyPressEventArgs object which contains a
> member named KeyChar. This member contains the ASCII character code. You

can
> use this in several ways....
>
> Sub keypressed(ByVal o As [Object], ByVal e As KeyPressEventArgs)
> ' Using the character code
> If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
> e.Handled = True
> End If
> ' Using the Keys enumeration
> If e.KeyChar = Keys.Enter Then
> e.Handled = True
> End If
> End Sub 'keypressed
>
>
> "Lumpierbritches" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Thank you in advance for any and all assistance. Is there a way in

VB.Net
> to
> > call the ASCII equivilalent to each corresponding keypress?
> >
> > Similar to VB6, using KeyAscii?
> >
> > If KeyAscii <= 26 Then Exit Sub
> > Dim I As Integer
> >
> > I was able to pull ASCII codes for each letter or keypress, which this

> code
> > above. Is there a way to do this in DotNet?
> >
> > Michael

>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      3rd Mar 2004
* "Scott" <(E-Mail Removed)> scripsit:
> Sub keypressed(ByVal o As [Object], ByVal e As KeyPressEventArgs)


Why do you use "[", "]" here?

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Keyboard never prints ASCII characters <127 loupeter DIY PC 1 10th Jun 2006 04:53 AM
Re: ascii code for vb Armin Zingler Microsoft VB .NET 0 15th May 2005 04:24 PM
DOS ASCII Code vs Windows ASCII Code??? Daniel Olivares Microsoft Windows 2000 Developer 0 6th Apr 2004 11:02 PM
Change keyboard mapping of ascii Gary Microsoft Windows 2000 Hardware 0 23rd Jan 2004 06:50 PM
Re: ASCII code VManes Windows XP General 0 14th Aug 2003 05:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:05 AM.