CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    6

    Problem with hotkey binds

    Hello out there :-)

    I am making a macro program, which should write a text when i click on a specify key on keyboard. I use F keys from F1 to F10 and my program works fine...

    The only problem i get is that the F1 key call the Help-box and F2 call the Find-box e.g. but i wanted to know, if its possible on a easy way that would disable them, and only react on send text i wan't without calling these...

    I use GetAsyncKeystate Function with Boolean.

    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
    and my F1 key (Timer Tick) look like this:

    Code:
    Private Sub bindf1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bindf1.Tick
            Dim bindf1 As Boolean
            bindf1 = GetAsyncKeyState(Keys.F1)
            If bindf1 = True Then
                SendKeys.Send(F1_txt.Text)
                SendKeys.Send("{Enter}")
            End If
        End Sub
    It works great, but the only problem is it calls the HELP-box which i don't want...

    Thank you :-)

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Problem with hotkey binds

    I sat with a similar situation quite recently. There is no way to disable the built in functionality of a certain Key like F1 in a program, so however you manage to press the key, it will always do what it was intended to do.

    Or, so I thought

    Two APIs will be needed : UnregisterHotKey and RegisterHotKey. Once you have registered a certain Hotkey and override the WM_HOTKEY message; there you go!

    There is a component I use with success in cases like this, and you can find it here :

    http://www.codeproject.com/KB/vb/mcl...px?msg=1808073

    http://www.vbforums.com/showthread.php?t=249194

    Just a note : If there is absolutely no other keys that you can actually use for this purpose, then doing this is fine, you'll just have to remember that the F keys have specific functions people are accustomed to - I'd actually say that you should rather choose different keys...

    I hope my advice was helpful

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Problem with hotkey binds

    You know that's always going to bring a question down the line (a few months?) about Ctrl-Alt-Del...

    Look up GINA (which controls special keys)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this 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

Featured