|
-
Nov 1st, 2000, 08:53 AM
#1
Thread Starter
New Member
Hey dudes~
Im a young Vb programmer and Im now taking a few courses to get me into the language. I was wondering, how do you use the Keypress function anyhow? I already know the ascii# for all the keys i just dont know how to use the function
Private Sub Form_KeyPress(KeyAscii As Integer), where do you input the ascii key?
If anyone could help I would appreciate it.
-TacoTycoon
-
Nov 1st, 2000, 09:14 AM
#2
Whatever you place in this sub will be executed everytime any key of the keyboard is pressed. Keyascii is the ASCII value of the pressed key.
If, for example, you wish for your application to "Beep" every time you press the "a" key, you will have to insert code similar to this:
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
if chr(Keyascii) = "a" or chr(Keyascii) = "A" then
Beep
end if
end sub
I hope that's clear enough.
-
Nov 1st, 2000, 09:39 AM
#3
PowerPoster
That's not correct. The KeyPress function only processes the ASCII keys pressed, ie. A E X . and so on..
If you want to get all keys (especially the arrows ) you should use the KeyDown function which really gets all keys:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft
MsgBox "Pressed the LEFT key"
Case vbKeyRight
MsgBox "Pressed the RIGHT key"
Case vbKeyUp
MsgBox "Pressed the UP key"
Case vbKeyDown
MsgBox "Pressed the DOWN key"
Case Else
MsgBox "Pressed key, code = " & KeyCode
End Select
End Sub
-
Nov 1st, 2000, 04:26 PM
#4
Damn Fox!
Yeah, Fox is right. As usual...
The Keypress event does not work for ALL the keys on your keyboard, only the ones that can actually print something on screen, like letters and numbers for example. Any other key will be accessed through the KyDown or KeyUp event.
-
Nov 2nd, 2000, 08:24 AM
#5
transcendental analytic
HEhe, even Keydown doesn't receive all events from keys pressed, if you want all, and that means exactly all keys including printscreen and ctrl-alt-numlock-C-D-E-uparrow then you should use getasynckeystate api
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 2nd, 2000, 08:45 AM
#6
PowerPoster
...use DInput
-
Nov 2nd, 2000, 05:19 PM
#7
Fanatic Member
hehe
what r u all fighting about??? TacoTycoon just wants to know how to use the keypress function and he's just a bigenner so dont confuse ppl...
I do suggest though that keydown will get the job done if ur a bigenner.
all this api cals and stuff will get u confused... i bet TacoTycoon doesnt even know what api is... I didnt know it until i finished my first vb course!!!
good luck, to you
TacoTycoon
-
Nov 2nd, 2000, 05:53 PM
#8
I'm with Fox on this; DInput works more well than GetAsyncKeyState, however, you need to include the DX type library if you want to use DInput -- So there's a down side and an up side.
-
Nov 3rd, 2000, 09:53 AM
#9
transcendental analytic
Hey hey, what are we fighting about? I'll suggest just have a go with Keydown event and you don't need to put any extra dependencies in youar app
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 3rd, 2000, 12:23 PM
#10
Fanatic Member
Kedaman is right... listen to him for once!!!
after all, he's a guru!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|