VB.net 发送按键到游戏
VB.net send keypress to game
我看到了关于这个问题的其他问题,但 none 已经为我解决了,所以我来了。我正在尝试向游戏发送按键以保存进度(它是 64 位游戏)。到目前为止我编码的是:
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.Send(";") 但没有运气,游戏在 "GameName" 下运行但是按键需要在 window 下发送游戏 :
Blacked out is the game and under the first window is where the keypress needs to be sent
提前感谢您的帮助
我在我的应用程序中使用 InputSimulator
,效果很好。
https://inputsimulator.codeplex.com/
发送密钥可以这么简单。活跃的 window 会看到用户实际使用了这些键。
var sim = new InputSimulator();
sim.Keyboard.KeyPress(VirtualKeyCode.SPACE);
sim = null;
下面是可用于键盘的方法的屏幕截图。
您可以像这样模拟键盘输入到程序中:
<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
我看到了关于这个问题的其他问题,但 none 已经为我解决了,所以我来了。我正在尝试向游戏发送按键以保存进度(它是 64 位游戏)。到目前为止我编码的是:
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.Send(";") 但没有运气,游戏在 "GameName" 下运行但是按键需要在 window 下发送游戏 : Blacked out is the game and under the first window is where the keypress needs to be sent
提前感谢您的帮助
我在我的应用程序中使用 InputSimulator
,效果很好。
https://inputsimulator.codeplex.com/
发送密钥可以这么简单。活跃的 window 会看到用户实际使用了这些键。
var sim = new InputSimulator();
sim.Keyboard.KeyPress(VirtualKeyCode.SPACE);
sim = null;
下面是可用于键盘的方法的屏幕截图。
您可以像这样模拟键盘输入到程序中:
<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