Results 1 to 4 of 4

Thread: Question regarding the "KeyDown Event" ?

  1. #1

    Thread Starter
    Junior Member rastin's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    26

    Lightbulb 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.

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    that code works
    (except its nto vbGrey)
    try using Gray
    if thats not the colour you want
    use Colour hex numbers instead of constants

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    2. use the samething you did for vbKeyA for F10
    you just need to find the constants for F10
    so if constant is vbKeyF10

    VB Code:
    1. case vbKeyF10
    2.      end
    3. use form2.show to display the form

  4. #4
    Helger
    Guest
    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
  •  



Click Here to Expand Forum to Full Width