Results 1 to 7 of 7

Thread: Multi Key Hotkeys

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    5

    Multi Key Hotkeys

    Hello,

    I am working on a program and need to be able to use Multi-Key hotkeys to activate other forms w/in the same solution. Below is the bit of code that I am currently trying to use.

    Code:
        Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
            If e.KeyCode = Keys.ControlKey And Keys.NumPad1 Then
                GaleOpening.Show()
    
            End If
        End Sub
    When running this, pressing the control key activates the form, but I need the key combination of CTRL+Numpad1 to activate the form, and not just the control key. I have also tried wrapping the 2 keys in () and that did not work either. Any help would be greatly appreciated.

    Thanks in advance.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: Multi Key Hotkeys

    try this:

    Code:
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.Control AndAlso e.KeyCode = Keys.NumPad1 Then
            'key combination pressed
        End If
    End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    5

    Re: Multi Key Hotkeys

    Paul,

    I was just about to update my post saying that I figured it out. That is exactly why I tried and it worked. Thank you for your assistance anyway, it is much appreciated. On a side note, is there a way to send a String of text that includes a variable when a button is clicked?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: Multi Key Hotkeys

    how do you mean - send a string?
    containing what + send to what?

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    5

    Re: Multi Key Hotkeys

    I will be using it to send a predefined string of text that will include a variable that is input from the form that I am opening with the hotkey. I would like to send this to the active window where the cursor is, but not sure if that is a feasible option.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: Multi Key Hotkeys

    yeah no problem as long as the cursor is in an editing control that has focus.

    Code:
    Dim myVariable As String = "*here*"
    SendKeys.Send(String.Format("a simple string containing {0} a variable", myVariable))

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    5

    Re: Multi Key Hotkeys

    Paul,

    Thank you for your assistance sir, it it much appreciated.

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