Имитация нажатия клавиш в приложении - VB
Формулировка задачи:
в игре нужно постоянно нажимать пробел! подскажите как сделать чтобы это было автоматически?
Решение задачи: «Имитация нажатия клавиш в приложении»
textual
Листинг программы
Option Explicit Private Type MODULEENTRY32 dwSize As Long th32ModuleID As Long th32ProcessID As Long GlblcntUsage As Long ProccntUsage As Long modBaseAddr As Long modBaseSize As Long hModule As Long szModule As String * 256 szExePath As String * 260 End Type Private Type POINTAPI x As Long y As Long End Type Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Private Declare Function Module32First Lib "kernel32" (ByVal hSnapshot As Long, uProcess As MODULEENTRY32) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) Const KEYEVENTF_KEYUP = &H2 'событие отпускания клавиши Const VK_LWIN = &H5B 'левая клавиша, эмулирующая нажатие кнопки ПУСК Const VK_RWIN = &H5B 'левая клавиша, эмулирующая нажатие кнопки ПУСК Dim CursorPos As POINTAPI Dim hWin As Long Private Sub Timer1_Timer() Dim pid As Long Dim hSnapshot As Long Dim uProcess As MODULEENTRY32 GetCursorPos CursorPos hWin = WindowFromPoint(CursorPos.x, CursorPos.y) Call GetWindowThreadProcessId(hWin, pid) hSnapshot = CreateToolhelp32Snapshot(8, pid) uProcess.dwSize = Len(uProcess) Call Module32First(hSnapshot, uProcess) Label1.Caption = Left(uProcess.szExePath, InStr(uProcess.szExePath, Chr(0)) - 1) If Label1.Caption = "C:\Program Files\Mozilla Firefox\firefox.exe" Then Call keybd_event(VK_LWIN, 0, 0, 0) 'Hажимаем Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0) 'Отпускаем Else End If End Sub Private Sub Form_Load() With Timer1 .Interval = 50 .Enabled = True End With End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д