无法启用特定密钥进入在线游戏
Failed To enable Specific key into online games
你好,我测试了我的项目,它在桌面上运行良好,甚至在游戏聊天中也运行良好,但在游戏环境中,无法运行..
{{{{KeyboardHook}}} : (((Class)))
Imports System.Runtime.InteropServices
Public Class KeyboardHook
<DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)>
Private Overloads Shared Function SetWindowsHookEx(ByVal idHook As Integer, ByVal HookProc As KBDLLHookProc, ByVal hInstance As IntPtr, ByVal wParam As Integer) As Integer
End Function
<DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)>
Private Overloads Shared Function CallNextHookEx(ByVal idHook As Integer, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
End Function
<DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)>
Private Overloads Shared Function UnhookWindowsHookEx(ByVal idHook As Integer) As Boolean
End Function
<StructLayout(LayoutKind.Sequential)>
Private Structure KBDLLHOOKSTRUCT
Public vkCode As UInt32
Public scanCode As UInt32
Public flags As KBDLLHOOKSTRUCTFlags
Public time As UInt32
Public dwExtraInfo As UIntPtr
End Structure
<Flags()>
Private Enum KBDLLHOOKSTRUCTFlags As UInt32
LLKHF_EXTENDED = &H1
LLKHF_INJECTED = &H10
LLKHF_ALTDOWN = &H20
LLKHF_UP = &H80
End Enum
Public Shared Event KeyDown(ByVal Key As Keys)
Public Shared Event KeyUp(ByVal Key As Keys)
Private Const WH_KEYBOARD_LL As Integer = 13
Private Const HC_ACTION As Integer = 0
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const WM_SYSKEYDOWN = &H104
Private Const WM_SYSKEYUP = &H105
Private Delegate Function KBDLLHookProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
Private KBDLLHookProcDelegate As KBDLLHookProc = New KBDLLHookProc(AddressOf KeyboardProc)
Private HHookID As IntPtr = IntPtr.Zero
Private Function KeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
If (nCode = HC_ACTION) Then
Dim struct As KBDLLHOOKSTRUCT
Select Case wParam
Case WM_KEYDOWN, WM_SYSKEYDOWN
RaiseEvent KeyDown(CType(CType(Marshal.PtrToStructure(lParam, struct.GetType()), KBDLLHOOKSTRUCT).vkCode, Keys))
Case WM_KEYUP, WM_SYSKEYUP
RaiseEvent KeyUp(CType(CType(Marshal.PtrToStructure(lParam, struct.GetType()), KBDLLHOOKSTRUCT).vkCode, Keys))
End Select
End If
Return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)
End Function
Public Sub New()
HHookID = SetWindowsHookEx(WH_KEYBOARD_LL, KBDLLHookProcDelegate, System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
If HHookID = IntPtr.Zero Then
Throw New Exception("Could not set keyboard hook")
End If
End Sub
Protected Overrides Sub Finalize()
If Not HHookID = IntPtr.Zero Then
UnhookWindowsHookEx(HHookID)
End If
MyBase.Finalize()
End Sub
End Class
-=-=-=-=-=-=
{{{Form1}}} : (((Vb)))
Public Class Form1
Private WithEvents kbHook As New KeyboardHook
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub kbHook_KeyDown(ByVal Key As System.Windows.Forms.Keys) Handles kbHook.KeyDown
Debug.WriteLine(Key.ToString)
If Key.ToString() = "G" Then
SendKeys.Send("R")
End If
If Key.ToString() = "J" Then
SendKeys.Send(" ")
End If
End Sub
Private Sub kbHook_KeyUp(ByVal Key As System.Windows.Forms.Keys) Handles kbHook.KeyUp
Debug.WriteLine(Key)
End Sub
End Class
我希望能有所帮助,我已经测试了代码并开始工作,但还没有进入游戏活动
所以当我点击 (g) 键时,将使用 (r) 按键重新加载,当我点击 (j) 键时,将点击空格键进入游戏。就这些,我不转发作弊,只是为了了解一下。
已更新(提供代码。)
SendKeys
在游戏中并不总是有效。尝试使用名为 InputHelper 的库 (Download from GitHub)。它有两种不同的输入模拟方法,并包含一个 easy-to-use 键盘挂钩。
只需确保在您的应用程序中或应用程序中的某处包含其版权许可,用户可以轻松找到它。
Imports InputHelperLib
Public Class Form1
Dim WithEvents KeyboardHook As New InputHelper.Hooks.KeyboardHook
Private Sub KeyboardHook_KeyDown(sender As Object, e As InputHelperLib.InputHelper.Hooks.KeyboardHookEventArgs) Handles KeyboardHook.KeyDown
Select Case e.KeyCode
Case Keys.G
InputHelper.Keyboard.PressKey(Keys.R)
Case Keys.J
InputHelper.Keyboard.PressKey(Keys.Space)
End Select
End Sub
End Class
如果这不起作用,您可以尝试使用其他两种发送按键的方法。
或者:
Select Case e.KeyCode
Case Keys.G
InputHelper.Keyboard.PressKey(Keys.R, True)
Case Keys.J
InputHelper.Keyboard.PressKey(Keys.Space, True)
End Select
或:
Select Case e.KeyCode
Case Keys.G
InputHelper.WindowMessages.SendKeyPress(Keys.R)
Case Keys.J
InputHelper.WindowMessages.SendKeyPress(Keys.Space)
End Select
我还没有记录库的其余部分,但在我的项目的 Wiki 中,您可以找到有关挂钩如何工作的信息。
尽管所有方法都添加了 XML 文档,因此 Visual Studio 的 IntelliSense 将向您展示它们及其参数的作用。您也可以在 VS 中按 F12 并在对象浏览器中查看 InputHelper 的所有成员。
请注意,有些游戏只接受原始硬件输入(即直接从 keyboard/mouse 读取)。如果您尝试使用的游戏是这种情况,那么您找到的大多数解决方案都不会奏效。
模拟输入的常规方法是将其附加到系统的鼠标和键盘输入流,或者将按键消息(window消息)发送到游戏window。但是,如果游戏只直接从输入设备获取原始输入,它会忽略这些。
您可以尝试谷歌搜索 "DirectX input simulation" 或 "DirectInput input simulation",但我怀疑您会找到有用的东西.
你好,我测试了我的项目,它在桌面上运行良好,甚至在游戏聊天中也运行良好,但在游戏环境中,无法运行..
{{{{KeyboardHook}}} : (((Class)))
Imports System.Runtime.InteropServices
Public Class KeyboardHook
<DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)>
Private Overloads Shared Function SetWindowsHookEx(ByVal idHook As Integer, ByVal HookProc As KBDLLHookProc, ByVal hInstance As IntPtr, ByVal wParam As Integer) As Integer
End Function
<DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)>
Private Overloads Shared Function CallNextHookEx(ByVal idHook As Integer, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
End Function
<DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)>
Private Overloads Shared Function UnhookWindowsHookEx(ByVal idHook As Integer) As Boolean
End Function
<StructLayout(LayoutKind.Sequential)>
Private Structure KBDLLHOOKSTRUCT
Public vkCode As UInt32
Public scanCode As UInt32
Public flags As KBDLLHOOKSTRUCTFlags
Public time As UInt32
Public dwExtraInfo As UIntPtr
End Structure
<Flags()>
Private Enum KBDLLHOOKSTRUCTFlags As UInt32
LLKHF_EXTENDED = &H1
LLKHF_INJECTED = &H10
LLKHF_ALTDOWN = &H20
LLKHF_UP = &H80
End Enum
Public Shared Event KeyDown(ByVal Key As Keys)
Public Shared Event KeyUp(ByVal Key As Keys)
Private Const WH_KEYBOARD_LL As Integer = 13
Private Const HC_ACTION As Integer = 0
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const WM_SYSKEYDOWN = &H104
Private Const WM_SYSKEYUP = &H105
Private Delegate Function KBDLLHookProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
Private KBDLLHookProcDelegate As KBDLLHookProc = New KBDLLHookProc(AddressOf KeyboardProc)
Private HHookID As IntPtr = IntPtr.Zero
Private Function KeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
If (nCode = HC_ACTION) Then
Dim struct As KBDLLHOOKSTRUCT
Select Case wParam
Case WM_KEYDOWN, WM_SYSKEYDOWN
RaiseEvent KeyDown(CType(CType(Marshal.PtrToStructure(lParam, struct.GetType()), KBDLLHOOKSTRUCT).vkCode, Keys))
Case WM_KEYUP, WM_SYSKEYUP
RaiseEvent KeyUp(CType(CType(Marshal.PtrToStructure(lParam, struct.GetType()), KBDLLHOOKSTRUCT).vkCode, Keys))
End Select
End If
Return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)
End Function
Public Sub New()
HHookID = SetWindowsHookEx(WH_KEYBOARD_LL, KBDLLHookProcDelegate, System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
If HHookID = IntPtr.Zero Then
Throw New Exception("Could not set keyboard hook")
End If
End Sub
Protected Overrides Sub Finalize()
If Not HHookID = IntPtr.Zero Then
UnhookWindowsHookEx(HHookID)
End If
MyBase.Finalize()
End Sub
End Class
-=-=-=-=-=-=
{{{Form1}}} : (((Vb)))
Public Class Form1
Private WithEvents kbHook As New KeyboardHook
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub kbHook_KeyDown(ByVal Key As System.Windows.Forms.Keys) Handles kbHook.KeyDown
Debug.WriteLine(Key.ToString)
If Key.ToString() = "G" Then
SendKeys.Send("R")
End If
If Key.ToString() = "J" Then
SendKeys.Send(" ")
End If
End Sub
Private Sub kbHook_KeyUp(ByVal Key As System.Windows.Forms.Keys) Handles kbHook.KeyUp
Debug.WriteLine(Key)
End Sub
End Class
我希望能有所帮助,我已经测试了代码并开始工作,但还没有进入游戏活动
所以当我点击 (g) 键时,将使用 (r) 按键重新加载,当我点击 (j) 键时,将点击空格键进入游戏。就这些,我不转发作弊,只是为了了解一下。
已更新(提供代码。)
SendKeys
在游戏中并不总是有效。尝试使用名为 InputHelper 的库 (Download from GitHub)。它有两种不同的输入模拟方法,并包含一个 easy-to-use 键盘挂钩。
只需确保在您的应用程序中或应用程序中的某处包含其版权许可,用户可以轻松找到它。
Imports InputHelperLib
Public Class Form1
Dim WithEvents KeyboardHook As New InputHelper.Hooks.KeyboardHook
Private Sub KeyboardHook_KeyDown(sender As Object, e As InputHelperLib.InputHelper.Hooks.KeyboardHookEventArgs) Handles KeyboardHook.KeyDown
Select Case e.KeyCode
Case Keys.G
InputHelper.Keyboard.PressKey(Keys.R)
Case Keys.J
InputHelper.Keyboard.PressKey(Keys.Space)
End Select
End Sub
End Class
如果这不起作用,您可以尝试使用其他两种发送按键的方法。
或者:
Select Case e.KeyCode
Case Keys.G
InputHelper.Keyboard.PressKey(Keys.R, True)
Case Keys.J
InputHelper.Keyboard.PressKey(Keys.Space, True)
End Select
或:
Select Case e.KeyCode
Case Keys.G
InputHelper.WindowMessages.SendKeyPress(Keys.R)
Case Keys.J
InputHelper.WindowMessages.SendKeyPress(Keys.Space)
End Select
我还没有记录库的其余部分,但在我的项目的 Wiki 中,您可以找到有关挂钩如何工作的信息。
尽管所有方法都添加了 XML 文档,因此 Visual Studio 的 IntelliSense 将向您展示它们及其参数的作用。您也可以在 VS 中按 F12 并在对象浏览器中查看 InputHelper 的所有成员。
请注意,有些游戏只接受原始硬件输入(即直接从 keyboard/mouse 读取)。如果您尝试使用的游戏是这种情况,那么您找到的大多数解决方案都不会奏效。
模拟输入的常规方法是将其附加到系统的鼠标和键盘输入流,或者将按键消息(window消息)发送到游戏window。但是,如果游戏只直接从输入设备获取原始输入,它会忽略这些。
您可以尝试谷歌搜索 "DirectX input simulation" 或 "DirectInput input simulation",但我怀疑您会找到有用的东西.