Results 1 to 7 of 7

Thread: [RESOLVED] Shortcut Key Creator

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Location
    Clive, IA in America!!!!
    Posts
    204

    Resolved [RESOLVED] Shortcut Key Creator

    I don't know if this is possible...

    I am creating a program that I want to show when the user types a shortcut on the keyboard. The thing is, I want the user to be able to custom create the shortcut on the form.

    As an example, if you right-mouse-click on a shortcut on the desktop and select properties, and select the shortcut tab, you can create a custom key stroke to run that shortcut. I want that textbox on my form.

    I have everything working accept for ctrl+shift+E and a few others. For some reason just a handful won't work.

    Here is the code I have:
    Code:
    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
            If e.KeyCode = Keys.ControlKey Then
                If e.Alt Then
                    If e.Shift Then
                        Me.TextBox1.Text = "Ctrl + Alt + Shift + "
                    Else
                        Me.TextBox1.Text = "Ctrl + Alt + "
                    End If
                Else
                    If e.Shift Then
                        Me.TextBox1.Text = "Ctrl + Shift + "
                    Else
                        Me.TextBox1.Text = "Ctrl + "
                    End If
                End If
    
                Exit Sub
            ElseIf e.KeyCode = Keys.ShiftKey Then
                If e.Control Then
                    If e.Alt Then
                        Me.TextBox1.Text = "Ctrl + Alt + Shift + "
                    Else
                        Me.TextBox1.Text = "Ctrl + Shift + "
                    End If
                Else
                    If e.Alt Then
                        Me.TextBox1.Text = "Alt + Shift + "
                    End If
                End If
    
                Exit Sub
            ElseIf e.KeyCode = Keys.Menu Then
                If e.Control Then
                    If e.Shift Then
                        Me.TextBox1.Text = "Ctrl + Alt + Shift + "
                    Else
                        Me.TextBox1.Text = "Ctrl + Alt + "
                    End If
                Else
                    If e.Shift Then
                        Me.TextBox1.Text = "Alt + Shift + "
                    End If
                End If
    
                Exit Sub
            Else
                If e.Control Then
                    If e.Shift Then
                        If e.Alt Then
                            Me.TextBox1.Text = "Ctrl + Alt + Shift + " & UCase(Chr(e.KeyCode))
                        Else
                            Me.TextBox1.Text = "Ctrl + Shift + " & UCase(Chr(e.KeyCode))
                        End If
                    Else
                        If e.Alt Then
                            Me.TextBox1.Text = "Ctrl + Alt + " & UCase(Chr(e.KeyCode))
                        Else
                            Me.TextBox1.Text = "Ctrl + " & UCase(Chr(e.KeyCode))
                        End If
                    End If
                Else
                    If e.Shift Then
                        If e.Alt Then
                            Me.TextBox1.Text = "Alt + Shift + " & UCase(Chr(e.KeyCode))
                        End If
                    Else
                        If e.Alt Then
                            Me.TextBox1.Text = "Alt + " & UCase(Chr(e.KeyCode))
                        End If
                    End If
                End If
    
                Exit Sub
            End If
        End Sub

  2. #2
    New Member
    Join Date
    Oct 2009
    Posts
    13

    Re: Shortcut Key Creator

    My best guess would be... to create a Select Case list of all of the possible entries, compare them to what the user has entered, and then make the Short Cut from there.

  3. #3
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Shortcut Key Creator

    I think you need to 'hook' the keyboard to do this. Check out this link or this for some helpful (I think) links.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Location
    Clive, IA in America!!!!
    Posts
    204

    Re: Shortcut Key Creator

    ForumDoe:

    Do you mean to make a list:

    Ctrl + Alt + A
    Ctrl + Alt + B
    Ctrl + Alt + C
    Ctrl + Alt + D
    ...
    Ctrl + Alt + Shift + A
    Ctrl + Alt + Shift + B
    Ctrl + Alt + Shift + C
    Ctrl + Alt + Shift + D
    ...
    Ctrl + Shift + A
    Ctrl + Shift + B
    Ctrl + Shift + C
    Ctrl + Shift + D
    ...

    That would be quite exhausting... there must be a better way!


    tassa:

    I already have a global keyboard hook built into my program, but I'm not sure how I would use it... I will try to work it out. In the meantime, do you know of an example that I can look at?

    I am soooo close! Just a few shortcuts that don't don't work... I'm thinking that the main form is 'clearing' the keystrokes. Kind of like a the read only textbox doesn't register the Ctrl + E keystroke. Would there be any way to bypass that (if that could be a solution).

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Location
    Clive, IA in America!!!!
    Posts
    204

    Re: Shortcut Key Creator

    Ahhhhh... Success!!!! Thank you, tassa, for your key board hook idea. I checked to see if the focus was in the text box, then used my existing global hook to find the key strokes! Works perfectly now. I would never have thought to do that.

    For those reading this, I have included the global keyboard hook that I used. I spent quite a bit of time searching for this online!
    Attached Files Attached Files

  6. #6
    New Member
    Join Date
    Oct 2009
    Posts
    13

    Re: [RESOLVED] Shortcut Key Creator

    Do you mean to make a list:

    Ctrl + Alt + A
    Ctrl + Alt + B
    Ctrl + Alt + C
    Ctrl + Alt + D
    ...
    Ctrl + Alt + Shift + A
    Ctrl + Alt + Shift + B
    Ctrl + Alt + Shift + C
    Ctrl + Alt + Shift + D
    ...
    Ctrl + Shift + A
    Ctrl + Shift + B
    Ctrl + Shift + C
    Ctrl + Shift + D
    ...
    I'm glad you got it figured out. But, for future reference, no, that wasn't what I was talking about.

    I suggested you make one list, A-Z, then allow the user to select which alter keys they wanted to use. Be that Ctrl, Alt, or Shift, or any other key you deemed necessary. Which is quick, easy and simple.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Location
    Clive, IA in America!!!!
    Posts
    204

    Re: [RESOLVED] Shortcut Key Creator

    Ahh... I see. Yeah... I kind of wanted to save space since I will need it. That's not a bad idea. I have seen it in a few other programs, come to think of it. And it would be very easy to do.... Anyhow, thanks for the post!

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