By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,369 Members | 966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,369 IT Pros & Developers. It's quick & easy.

Ascii Codes

sgrec7
P: 59
hi guys,

hey i looked everywere and i can't for the life of me find the ascii codes for these keys:

ctrl (the control button, bottom left corner of keyboard)

alt (the alt button, either side of the spacebar)

thanks guys, even if you link me the URL for a site that will help

thanks again in advance

sgrec7
Sep 3 '07 #1
Share this Question
Share on Google+
13 Replies


kadghar
Expert 100+
P: 1,295
hi guys,

hey i looked everywere and i can't for the life of me find the ascii codes for these keys:

ctrl (the control button, bottom left corner of keyboard)

alt (the alt button, either side of the spacebar)

thanks guys, even if you link me the URL for a site that will help

thanks again in advance

sgrec7
ctrl ---> 17
alt ---> 18

you can have it on a text box if you write in some other controls KeyDown event something like

textbox1.text = keycode

then just select that control an press the key you want to know ;)
Sep 4 '07 #2

Expert 5K+
P: 8,434
These keys don't have ASCII codes.

ASCII defines values for the character set. These are keyboard keys, not characters.

The difference between KeyDown and KeyPress events is that one reports the actual key pressed, while the other reports the ASCII character which was generated as a result. For example, pressing the "A" key generates the keycode for that key (65). Depending on the current state of the Caps-Lock, Shift, Control and Alt and Shift keys, the ASCII character generated might be...
"A" (code 65), "a" (code 97), "Ctrl-A" (code 1) or whatever.
This is why keys such as Shift, Alt and so on do not trigger a KeyPress event.
Sep 4 '07 #3

sgrec7
P: 59
yea thanks guys...

i want to use alt and ctrl in a keyprss event

will it still work ???
Sep 4 '07 #4

hariharanmca
100+
P: 1,977
yea thanks guys...

i want to use alt and ctrl in a keyprss event

will it still work ???
You can try Key down and key up event using

KeyCode = vbKeyControl ==>> Control
KeyCode = vbKeyMenu ==>> Alt

there you find two perameter for key pressed and shift pressed

I think this will help you.
Sep 4 '07 #5

Expert 5K+
P: 8,434
i want to use alt and ctrl in a keyprss event
Are you sure you can't do it in the KeyDown or KeyUp event?

If you want, you can put code in your KeyPress event procedure to test the current state of these keys. I forget how, but detecting the current state of keys was covered here not too long ago. Maybe a couple of months back. Try some searches.
Sep 4 '07 #6

QVeen72
Expert 100+
P: 1,445
Hi,

U have to check the Shift in KeyUp event :
Values would be:
A C S
4 2 1

Expand|Select|Wrap|Line Numbers
  1. Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
  2.   Select Case Shift
  3.          Case 1
  4.              MsgBox "Shift Pressed"
  5.          Case 2
  6.              MsgBox "Control Pressed"
  7.          Case 3
  8.              MsgBox "Shift + Control Pressed"
  9.          Case 4
  10.              MsgBox "Alt Pressed"
  11.          Case 5
  12.              MsgBox "Alt + Shift Pressed"
  13.          Case 6
  14.              MsgBox "Alt+Control Pressed"
  15.         Case 7
  16.              MsgBox "Alt+Shift+Control Pressed"
  17.   End Select
  18. End Sub
  19.  
REgards
Veena
Sep 4 '07 #7

Expert 5K+
P: 8,434
There's also an API function you can call to check the current key state. I just don't remember what it's called.
Sep 4 '07 #8

sgrec7
P: 59
Are you sure you can't do it in the KeyDown or KeyUp event?

If you want, you can put code in your KeyPress event procedure to test the current state of these keys. I forget how, but detecting the current state of keys was covered here not too long ago. Maybe a couple of months back. Try some searches.
or you could just tell me !!! :-) that would be MUCH easer... for me !!! :-)
Sep 5 '07 #9

Expert 5K+
P: 8,434
or you could just tell me !!! :-) that would be MUCH easer... for me !!! :-)
It certainly would. If I could remember it. I do remember it had "Asynch" in the name, but that's probably not a lot of help.
Sep 5 '07 #10

Expert 5K+
P: 8,434
Ok, I spent some time searching, and managed to track down the thread I was thinking of. Here it is.

I hope it's some help.
Sep 5 '07 #11

QVeen72
Expert 100+
P: 1,445
or you could just tell me !!! :-) that would be MUCH easer... for me !!! :-)
Hi,

did u check my post above...?


Regards
Veena
Sep 5 '07 #12

kadghar
Expert 100+
P: 1,295
or you could just tell me !!! :-) that would be MUCH easer... for me !!! :-)
In my first post i wrote what the KeyCode were, and as Killer said, they dont have an ascii code, only a KeyCode. (the keycodes are 17 and 18), and im not sure they'll work in keypress, you should use them in keydown
Sep 5 '07 #13

sgrec7
P: 59
In my first post i wrote what the KeyCode were, and as Killer said, they dont have an ascii code, only a KeyCode. (the keycodes are 17 and 18), and im not sure they'll work in keypress, you should use them in keydown
Thanks to all of you, but after reading through all that I think we will come to an agreement that space bar (32) will be much easier to deal with

thanks to you all again

sgrec7
Sep 5 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.