代码之家  ›  专栏  ›  技术社区  ›  sniperfull

VB.net发送按键到游戏

  •  0
  • sniperfull  · 技术社区  · 7 年前

    Dim p() As Process
    Dim GameID As Integer = 0
     Dim p As Process() = Process.GetProcessesByName("Gamename")
    
        If p.Length > 0 Then
            For i As Integer = 0 To p.Length - 1
                GameID = (p(i).Id)
            Next
        End If
    AutoSaveTimer.Enabled = True
        Dim Test As Integer = 0
        GetAsyncKeyState(Test)
        AppActivate("GameName")
        My.Computer.Keyboard.SendKeys(";", True)
    

    现在我已经试过Sendkeys了。发送(“;”)但是如果没有运气,游戏在“GameName”下运行,但需要在游戏下方的窗口中发送按键: Blacked out is the game and under the first window is where the keypress needs to be sent

    提前感谢您的帮助

    2 回复  |  直到 7 年前
        1
  •  0
  •   Michael Z.    7 年前

    InputSimulator 在我的应用程序中,它工作得很好。

    https://inputsimulator.codeplex.com/

    发送钥匙可能就这么容易。活动窗口将看到,就好像用户实际使用了这些键一样。

    var sim = new InputSimulator();
    sim.Keyboard.KeyPress(VirtualKeyCode.SPACE);
    sim = null;
    

    enter image description here

        2
  •  0
  •   Michael Z.    7 年前

        <DllImport("user32.dll")> _
    Public Shared Function SetForegroundWindow(hWnd As IntPtr) As Boolean
    End Function
    
    Public Sub Send()
            Dim p As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("notepad")
            'search for process notepad
            If p.Length > 0 Then
                'check if window was found
                'bring notepad to foreground
                SetForegroundWindow(p(0).MainWindowHandle)
            End If
    
            SendKeys.SendWait("a")
            'send key "a" to notepad
        End Sub