locked
Shortcuts RRS feed

  • Question

  • Hello,

    I am an application to make and I sit with the following problem. I want to add shortcuts to my program. The F10 key word. But the shortcut should work even if the program is not focused. How do I do this?

    Tim Visée

    www.t-soft.nl
    Saturday, September 11, 2010 11:45 PM

Answers

  • use GetAsyncKeyState API with timer to detect when key is press on keyboard.

    try the code below

    Imports System.Runtime.InteropServices
        'API
        Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As System.Int32) As Integer
        ' VK_F10 (0x79) F10 key
        Dim f10 As Int32 = Convert.ToInt32(&H79)
        Function checkF10(ByVal vkey As Int32) As Boolean
            If GetAsyncKeyState(vkey) Then
                Return True
            End If
            Return False
        End Function
        Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
            Dim IsF10Key As Boolean = checkF10(f10)
            If IsF10Key = True Then
                'do something
            End If
        End Sub

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    • Marked as answer by Tim Visee Sunday, September 12, 2010 9:16 AM
    • Unmarked as answer by Tim Visee Sunday, September 12, 2010 10:05 AM
    • Marked as answer by Tim Visee Sunday, September 12, 2010 2:45 PM
    Sunday, September 12, 2010 12:15 AM
  • Add the same test for the F12 key.  The key codes are listed here:

    http://msdn.microsoft.com/en-us/library/ms927178.aspx

    • Marked as answer by Tim Visee Sunday, September 12, 2010 2:45 PM
    Sunday, September 12, 2010 10:51 AM

All replies

  • use GetAsyncKeyState API with timer to detect when key is press on keyboard.

    try the code below

    Imports System.Runtime.InteropServices
        'API
        Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As System.Int32) As Integer
        ' VK_F10 (0x79) F10 key
        Dim f10 As Int32 = Convert.ToInt32(&H79)
        Function checkF10(ByVal vkey As Int32) As Boolean
            If GetAsyncKeyState(vkey) Then
                Return True
            End If
            Return False
        End Function
        Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
            Dim IsF10Key As Boolean = checkF10(f10)
            If IsF10Key = True Then
                'do something
            End If
        End Sub

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    • Marked as answer by Tim Visee Sunday, September 12, 2010 9:16 AM
    • Unmarked as answer by Tim Visee Sunday, September 12, 2010 10:05 AM
    • Marked as answer by Tim Visee Sunday, September 12, 2010 2:45 PM
    Sunday, September 12, 2010 12:15 AM
  • Thanks!
    www.t-soft.nl
    Sunday, September 12, 2010 9:15 AM
  • But how to do this with the F12 key?


    www.t-soft.nl
    Sunday, September 12, 2010 10:08 AM
  • Add the same test for the F12 key.  The key codes are listed here:

    http://msdn.microsoft.com/en-us/library/ms927178.aspx

    • Marked as answer by Tim Visee Sunday, September 12, 2010 2:45 PM
    Sunday, September 12, 2010 10:51 AM
  • THANKS!
    www.t-soft.nl
    Sunday, September 12, 2010 2:43 PM