Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Windows API
- ' code to send keypress to control..
- '
- ' emulates AutoIT ControlSend("WindowText", "", "[CLASS:... INSTANCE=1]", "^{F10}")
- <DllImport("user32.dll")> _
- Private Shared Function GetKeyboardState(ByVal keyState() As Byte) As Boolean
- End Function
- <DllImport("user32.dll")> _
- Private Shared Function SetKeyboardState(lpKeyState() As Byte) As Boolean
- End Function
- <DllImport("user32.dll")> _
- Private Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean
- End Function
- <DllImport("user32.dll")> Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
- End Function
- <DllImport("kernel32.dll")> _
- Public Shared Function GetCurrentThreadId() As Integer
- End Function
- <DllImport("user32.dll", SetLastError:=True)> _
- Private Shared Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, _
- ByRef lpdwProcessId As Integer) As Integer
- End Function
- <DllImport("user32.dll")> _
- Public Shared Function AttachThreadInput(ByVal idAttach As System.UInt32, ByVal idAttachTo As System.UInt32, ByVal fAttach As Boolean) As Boolean
- End Function
- 'Emulates WinAttach AutoIt procedure
- Private Sub WinAttach(hwnd As IntPtr, bAttach As Boolean)
- Dim myThread As Integer
- Dim newThread As Integer
- Dim curThread As Integer
- myThread = GetCurrentThreadId()
- If bAttach = True Then
- curThread = GetWindowThreadProcessId(hwnd, Nothing)
- AttachThreadInput(myThread, curThread, True)
- newThread = GetWindowThreadProcessId(hwnd, Nothing)
- AttachThreadInput(curThread, newThread, True)
- AttachThreadInput(myThread, newThread, True)
- Else
- AttachThreadInput(myThread, newThread, False)
- AttachThreadInput(curThread, newThread, False)
- AttachThreadInput(myThread, curThread, False)
- End If
- End Sub
- Private Sub EmulateCTRLF10()
- Dim kbState(255) As Byte
- GetKeyboardState(kbState)
- kbState(17) = &H80 //Set CTRL as pressed
- SetKeyboardState(kbState)
- PostMessage(hWnd, &H100, 17, 1900545) 'press ctrl
- PostMessage(hWnd, &H100, 121, 4456449) 'press f10
- PostMessage(hWnd, &H101, 121, &HC0440001) 'unpress f10
- PostMessage(hWnd, &H101, 17, &HC01D0001) 'unpress ctrl
- End Sub
- ' The sub EmulateCTRLF10 must be started in another thread.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement