|
-
Oct 17th, 2001, 08:18 AM
#1
Thread Starter
Junior Member
Question regarding the "KeyDown Event" ?
Hi,
As you can see from the code below, I've included this code on a form which changes the backcolor to blue every time I press the "a" key on the keyboard.
When the key is released it changes the form color back to gray.
My questions are;
1. How do I make it respond only at the pressing of a capital "A" key?
2. What code do I use to quit the program by pressing the "F10" key?
3. What code do I use to display another form?
Thanks,
Rastin
My code for QUESTION 1.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyA
Form1.BackColor = vbBlue
End Select
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Form1.BackColor = vbGray
End Sub
Last edited by rastin; Oct 17th, 2001 at 08:23 AM.
-
Oct 17th, 2001, 08:22 AM
#2
Frenzied Member
that code works
(except its nto vbGrey)
try using Gray
if thats not the colour you want
use Colour hex numbers instead of constants
-
Oct 17th, 2001, 08:25 AM
#3
Frenzied Member
2. use the samething you did for vbKeyA for F10
you just need to find the constants for F10
so if constant is vbKeyF10
3. use form2.show to display the form
-
Oct 17th, 2001, 08:33 AM
#4
Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
the shift parameter:
case vbkeyA
if shift = 1 then
'do stuff
end if
put a debug.print shift in your code to see which values you get for shift. it will change for alt, strg and shift and will be different for combinations...
Helger
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
|