2019. 8. 28. 20:25

Imports System.Runtime.InteropServices

Module Module1


    Private Const VK_H As Short = 72
    Private Const VK_E As Short = 69
    Private Const VK_L As Short = 76
    Private Const VK_O As Short = 79

    Private Const KEYEVENTF_KEYUP As Integer = &H2
    Private Const INPUT_MOUSE As Integer = 0
    Private Const INPUT_KEYBOARD As Integer = 1
    Private Const INPUT_HARDWARE As Integer = 2

    Private Structure MOUSEINPUT
        Public dx As Integer
        Public dy As Integer
        Public mouseData As Integer
        Public dwFlags As Integer
        Public time As Integer
        Public dwExtraInfo As IntPtr
    End Structure

    Private Structure KEYBDINPUT
        Public wVk As Short
        Public wScan As Short
        Public dwFlags As Integer
        Public time As Integer
        Public dwExtraInfo As IntPtr
    End Structure

    Private Structure HARDWAREINPUT
        Public uMsg As Integer
        Public wParamL As Short
        Public wParamH As Short
    End Structure

    <StructLayout(LayoutKind.Explicit)>
    Private Structure INPUT
        <FieldOffset(0)>
        Public type As Integer
        <FieldOffset(4)>
        Public mi As MOUSEINPUT
        <FieldOffset(4)>
        Public ki As KEYBDINPUT
        <FieldOffset(4)>
        Public hi As HARDWAREINPUT
    End Structure

    Private Declare Function SendInput Lib "user32" (ByVal nInputs As Integer, ByVal pInputs() As INPUT, ByVal cbSize As Integer) As Integer
    Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As IntPtr, ByVal idAttachTo As IntPtr, ByVal fAttach As Boolean) As Boolean
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As IntPtr, ByVal lpwdProcessId As IntPtr) As IntPtr
    Private Declare Function GetCurrentThreadId Lib "kernel32" () As IntPtr
    Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As IntPtr) As Boolean

    Private Sub SendKey(ByVal bKey As Short)
        Dim GInput(1) As INPUT

        ' press the key
        GInput(0).type = INPUT_KEYBOARD
        GInput(0).ki.wVk = bKey
        GInput(0).ki.dwFlags = 0

        ' release the key
        GInput(1).type = INPUT_KEYBOARD
        GInput(1).ki.wVk = bKey
        GInput(1).ki.dwFlags = KEYEVENTF_KEYUP

        SendInput(2, GInput, Marshal.SizeOf(GetType(INPUT)))

    End Sub

    Private Const VK_0 As Short = 48
    Private Const VK_1 As Short = 49
    Private Const VK_2 As Short = 50
    Private Const VK_3 As Short = 51
    Private Const VK_4 As Short = 52
    Private Const VK_5 As Short = 53
    Private Const VK_6 As Short = 54
    Private Const VK_7 As Short = 55
    Private Const VK_8 As Short = 56
    Private Const VK_9 As Short = 57
    Private Const VK_Et As Short = 13
    Private Const VK_Dn As Short = 40


    Sub Main(key As Short)
        'Dim notepad As Process = Process.Start("notepad.exe")
        'If notepad.WaitForInputIdle() Then

        'Dim hNotePad As IntPtr = notepad.MainWindowHandle
        Dim hNotePad As IntPtr = FindWindow(Nothing, "####")

        Dim hNoteThread As IntPtr = GetWindowThreadProcessId(hNotePad, IntPtr.Zero)

        If hNoteThread <> IntPtr.Zero Then
            If AttachThreadInput(GetCurrentThreadId(), hNoteThread, True) Then

                'SetForegroundWindow(hNotePad)
                SendKey(key)
                'SendKey(VK_Dn)
                'SendKey(VK_Et)
                'SendKey(VK_E)
                'SendKey(VK_L)
                'SendKey(VK_L)
                'SendKey(VK_O)

                AttachThreadInput(GetCurrentThreadId(), hNotePad, False)
            End If
        End If
        'End If
    End Sub
End Module

'VB.NET' 카테고리의 다른 글

VB.NET 이미지서치 ImageSearchDLL.dll  (1) 2021.03.16
VB.NET FindWindow, FindWindowEX API  (0) 2021.03.15
alert 없애기  (0) 2020.07.11
웹연동 소스  (0) 2020.07.11
유틸리티 Microsoft Spy++ V10.0 다운로드  (0) 2019.11.04
유틸리티 API뷰어(Winapi) 다운로드  (0) 2019.11.03
웹연동  (0) 2019.08.26
참조 추가 Management  (0) 2019.08.20
핸들값  (0) 2019.08.12
좌표를 합친 롱 값을 만든다.  (0) 2019.08.11
Posted by 블로그(8109)