키보드 이벤트 발생 예제
*
Imports VK = System.Windows.Forms.Keys

Public Class Form1
Public Class Keyboard_Event
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Integer, ByVal wMapType As Integer) As Integer
Public Const KEYEVENTF_KEYUP As Short = &H2S
Private Sub PressKey(ByVal VK As Byte, ByVal Scan As Byte)
keybd_event(VK, Scan, 0, 0)
keybd_event(VK, Scan, KEYEVENTF_KEYUP, 0)
End Sub
Public Sub Key_Press(ByRef Key As Windows.Forms.Keys)
Dim ScanKey As Short
ScanKey = MapVirtualKey(Key, 0)
PressKey(Key, ScanKey)
End Sub
Public Sub KeyDown(ByRef Key As Windows.Forms.Keys)
Dim ScanKey As Short
ScanKey = MapVirtualKey(Key, 0)
keybd_event(Key, ScanKey, 0, 0)
End Sub
Public Sub KeyUp(ByRef Key As Windows.Forms.Keys)
Dim ScanKey As Short
ScanKey = MapVirtualKey(Key, 0)
keybd_event(Key, ScanKey, KEYEVENTF_KEYUP, 0)
End Sub
End Class

Public Sub Delay(Optional ByRef dTime As Single = 1)
Dim sTime As Single
sTime = Microsoft.VisualBasic.Timer()
Do
System.Windows.Forms.Application.DoEvents()
If sTime > Microsoft.VisualBasic.Timer() Then sTime = sTime - 86400
Loop While dTime + sTime > Microsoft.VisualBasic.Timer()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim KeyBoard As Keyboard_Event = New Keyboard_Event
TextBox1.Focus()
Delay(1)
KeyBoard.Key_Press(VK.A)
KeyBoard.Key_Press(VK.B)
KeyBoard.Key_Press(VK.C)
KeyBoard.Key_Press(VK.D)
KeyBoard.Key_Press(VK.E)
KeyBoard.Key_Press(VK.F)
KeyBoard.Key_Press(VK.G)
KeyBoard.Key_Press(VK.H)
KeyBoard.Key_Press(VK.Tab)
End Sub


End Class

.

이 게시물을

공유하기

SEARCH

MENU NAVIGATION