Covey
Creator of EliteSwitch
Well since im about to move on from VB6 i don't see the point on keeping this too myself. (even though its not that great).
Note
This should only be used with RuneScape, if you try to use this for another program / game. It will not work correctly due to the Universal Charater conversion function.
And to those that want to know what the meaning of "Silent" is, well it simply sends the text to the given handle without actually having to have it as your Desktop Window.
Credits:
Jazz - KeyCode(ByVal sChar As String) Function
Cruel - Wait(TimeOut As Long) Sub
Note
This should only be used with RuneScape, if you try to use this for another program / game. It will not work correctly due to the Universal Charater conversion function.
And to those that want to know what the meaning of "Silent" is, well it simply sends the text to the given handle without actually having to have it as your Desktop Window.
Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hWnd As Long) As Long
Private Declare Function GetVersion Lib "kernel32" () As Long
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer
Private Declare Function VkKeyScanW Lib "user32" (ByVal cChar As Integer) As Integer
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const WM_CHAR = &H102
Private Const WM_SETFOCUS = &H7
Private Const WM_ACTIVATE = &H6
Private Sub Wait(TimeOut As Long)
Dim TimeNow As Long
TimeNow = GetTickCount
Do
DoEvents
Loop While TimeNow + TimeOut > GetTickCount
End Sub
Private Function KeyCode(ByVal sChar As String) As KeyCodeConstants
Dim bNt As Boolean
Dim iKeyCode As Integer
Dim b() As Byte
Dim iKey As Integer
Dim vKey As KeyCodeConstants
Dim iShift As ShiftConstants
bNt = ((GetVersion() And &H80000000) = 0)
If (bNt) Then
b = sChar
CopyMemory iKey, b(0), 2
iKeyCode = VkKeyScanW(iKey)
Else
b = StrConv(sChar, vbFromUnicode)
iKeyCode = VkKeyScan(b(0))
End If
KeyCode = (iKeyCode And &HFF&)
End Function
Public Sub SendText(wText As String, ByVal wHandle As Long, sTypeSpeed As Long)
Dim strChr As String
Dim wCount As Long
Dim wLen As Long
wLen = Len(wText)
Call SendMessage(wHandle, WM_SETFOCUS, True, ByVal 0&)
Do Until wCount >= wLen
Randomize
wCount = wCount + 1
strChr = Mid$(wText, wCount, 1)
Call SendMessage(wHandle, WM_KEYDOWN, KeyCode(strChr), ByVal 0&)
Call SendMessage(wHandle, WM_CHAR, KeyCode(strChr), ByVal 0&)
Wait Int(Rnd * 3) + 2
Call SendMessage(wHandle, WM_KEYUP, KeyCode(strChr), ByVal 0&)
Wait sTypeSpeed
Loop
Call SendMessage(wHandle, WM_KEYDOWN, KeyCode(Chr$(13)), ByVal 0&)
Call SendMessage(wHandle, WM_CHAR, KeyCode(Chr$(13)), ByVal 0&)
Wait Int(Rnd * 3) + 2
Call SendMessage(wHandle, WM_KEYUP, KeyCode(Chr$(13)), ByVal 0&)
Call SendMessage(wHandle, WM_ACTIVATE, True, ByVal 0&)
End Sub
Credits:
Jazz - KeyCode(ByVal sChar As String) Function
Cruel - Wait(TimeOut As Long) Sub


