Page 2 of 2

Re: Hotkey Help?

Posted: Tue Jan 17, 2012 1:56 am
by mandai
Hotkey mapping can be complex if you are doing it between different programs.

You can use this code to register a system-wide hotkey: viewtopic.php?f=32&t=7564&p=55919#p56005

Based on this code, you can use this sample to see if the game is in focus and then you could send some keys:
Code: Select all
    <DllImport("user32.dll")> Shared Function GetWindowText(ByVal hWnd As IntPtr, ByVal lpString As StringBuilder, ByVal nMaxCount As Integer) As Integer
    End Function

    <DllImport("user32.dll")> Shared Function GetForegroundWindow() As IntPtr
    End Function

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_HOTKEY Then

            Dim foreground As IntPtr = GetForegroundWindow()

            Dim sb As StringBuilder = New StringBuilder(255)
            GetWindowText(foreground, sb, sb.MaxCapacity)
            Dim winTitle As String = sb.ToString()

            If winTitle = "Untitled - Notepad" Then 'example
                SendKeys.SendWait("test")
            End If
        End If

        MyBase.WndProc(m)
    End Sub

Re: Hotkey Help?

Posted: Tue Jan 17, 2012 2:10 am
by upperdrag
I'm so sorry.. but i still do not understand how to use this code! Is it possible if you send a source code to me written in vb.net? Thanks a ton! Oh right.. is it possible to make a ingame menu in vb.net? It will be much convinent if you could just change the hotkeys ingame.


*Edit*
Nvm.... i've got it, seems like sendkeys work for that. Now.. How can i only activate the hotkeys when the game is focused, so that the hotkeys only work in the game and not anywhere else like notepad? Oh.. and how do i make user defined hotkeys?