HotKeys in VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ali Rizwan
    Banned
    Contributor
    • Aug 2007
    • 931

    HotKeys in VB6

    Hi
    How to assign hotkey to any command
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by Ali Rizwan
    Hi
    How to assign hotkey to any command
    If the Command Text Or Caption is "Click ME" and you want assigen M as Hot Key then change the caption to "Click &ME"

    Comment

    • Dave Siegel
      New Member
      • Feb 2007
      • 42

      #3
      Originally posted by hariharanmca
      If the Command Text Or Caption is "Click ME" and you want assigen M as Hot Key then change the caption to "Click &ME"
      I'm trying to do the same thing. But i want things to execute when someone say presses F1. I'm guessing that works different?

      Comment

      • hariharanmca
        Top Contributor
        • Dec 2006
        • 1977

        #4
        Originally posted by Dave Siegel
        I'm trying to do the same thing. But i want things to execute when someone say presses F1. I'm guessing that works different?

        1. Make Form Keypreview = True
        2. In Form Key Down Event

        [CODE=vb]If KeyCode = vbKeyF1 then Command1_Click[/CODE]

        Comment

        • Dave Siegel
          New Member
          • Feb 2007
          • 42

          #5
          Originally posted by hariharanmca
          1. Make Form Keypreview = True
          2. In Form Key Down Event

          [CODE=vb]If KeyCode = vbKeyF1 then Command1_Click[/CODE]
          Cheers.

          Helped alot.

          Comment

          • WinneRdk
            New Member
            • Oct 2008
            • 6

            #6
            I've tried it, but it doesn't work...
            Could you post the whole code please :)

            Comment

            • debasisdas
              Recognized Expert Expert
              • Dec 2006
              • 8119

              #7
              kindly post what you have tried.

              Comment

              • WinneRdk
                New Member
                • Oct 2008
                • 6

                #8
                I've tried this... But it didn't work

                Code:
                Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
                KeyPreview = True
                If KeyCodeConstants = vbKeyF1 Then Command1_Click
                If KeyCodeConstants = vbKeyF2 Then Command2_Click
                If KeyCodeConstants = vbKeyF3 Then Command3_Click
                If KeyCodeConstants = vbKeyF4 Then Command4_Click
                If KeyCodeConstants = vbKeyF5 Then Command5_Click
                If KeyCodeConstants = vbKeyF6 Then Command6_Click
                End Sub
                I've tried KeyCode instead of KeyCodeConstant s at first, but I tried to change it to this...

                Comment

                • debasisdas
                  Recognized Expert Expert
                  • Dec 2006
                  • 8119

                  #9
                  KeyPreview is a property of the form. You need to set that.
                  can be set at design time.

                  Comment

                  • WinneRdk
                    New Member
                    • Oct 2008
                    • 6

                    #10
                    So

                    Code:
                    Private Sub Form_Load()
                    KeyPreview = True
                    End Sub
                    It works!! :)
                    Thanks :)

                    Comment

                    • nicejohn123
                      New Member
                      • Jun 2009
                      • 1

                      #11
                      hotkeys

                      you also need to click on the form and change the key preview to true.



                      Private Sub Form_Load()
                      KeyPreview = True
                      If hotkey = vbKeyF1 Then Command1_Click
                      End Sub

                      Comment

                      Working...