Results 1 to 5 of 5

Thread: Assigning keys to command buttons.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    5

    Assigning keys to command buttons.

    Hello all. I've been searching all over for the solution for this. Hopefully someone here can help me with a code.

    Basically I want to assign the UP, DOWN, LEFT, RIGHT, and LEFT MOUSE keys to command buttons. So for example: when I click command1, it would function as the UP key, clicking command2 would function as the DOWN key, clicking command3 would function as the LEFT key, clicking command4 would function as the RIGHT key, and clicking command5 will function as the LEFT MOUSE key.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    5

    Re: Assigning keys to command buttons.

    Command1 would be vbKeyUp, Command2 would be vbKeyDown, Command3 would be vbKeyLeft, Command4 would be vbKeyRight, and Command5 would be vbKeyLButton.

    I'm not sure what the code would be.

  3. #3
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Assigning keys to command buttons.

    Set the KeyPreview mode of the form to True, then analyze it's KeyDown event to check which key is pressed, and act on received events.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Assigning keys to command buttons.

    Either I or baja have this backward but it looks to me like you want to press the command button and then have something happen. You didn't say what the Up, Down, etc is acting on but here is how you'd do Up for a textbox.

    Code:
    Private Sub Command1_Click()
        Text1.SetFocus
        SendKeys "{UP}"
    End Sub

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Assigning keys to command buttons.

    It's definitely me. I just read the original post again and I got it the other way around.

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