Results 1 to 3 of 3
  1. #1
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow

    StringSender's sauce.

    Hey guys, as you may or may not know I released a library called "StringSender.dll" a long time ago. The other day TimoTerremoto‎ had a problem with the dll so I decided to re-open the old project and see what the problem might have been. When I saw the code I'll admit I was a bit disgusted at how n00b I was back then; there was a LOT of poor coding going on there. Anyway, now I've freshened the code up a bit, I thought I'd share it with everyone.

    Unfortunately the syntax highlighting plugin isn't working so well.
    Code:
    Imports System.Runtime.InteropServices
    Public Class KeySender
    
        <DllImport("user32.dll", SetLastError:=True)> _
        Private Shared Function keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInt32, ByVal dwExtraInfo As UIntPtr) As Boolean
        End Function
    
        Public Shared Sub SendString(ByVal message As String, Optional ByVal pauseLength As Int32 = 0)
            Dim ASCII As String = message.ToUpper() '//Asc only works on upper case letters properly.
            For i As Integer = 0 To message.Length - 1 '//loop through the characters.
                Dim vk As Byte = CType(Asc(ASCII(i)), Byte)
                If Char.IsUpper(message(i)) Then 'check if the original character is uppercase
                    SendTwoKeys(16, vk) 'if so, send the shift key + the key.
                Else
                    SendKey(vk) 'otherwise just send the key.
                End If
                If pauseLength > 0 Then Threading.Thread.Sleep(pauseLength) 'if the user specified a pause length, pause for that time.
            Next i
        End Sub
    
        Public Shared Sub SendKey(ByVal vKeyCode As Byte)
            Try
                keybd_event(vKeyCode, 0, 0, UIntPtr.Zero) 'key down
                Threading.Thread.Sleep(5) 'very light tap on the keyboard.
                keybd_event(vKeyCode, 0, 2, UIntPtr.Zero) 'key up
            Catch ex As Exception
            End Try
        End Sub
    
        Public Shared Sub SendTwoKeys(ByVal firstKey As Byte, ByVal secondKey As Byte)
            Try
                keybd_event(firstKey, 0, 0, UIntPtr.Zero) 'hold down key 1
                keybd_event(secondKey, 0, 0, UIntPtr.Zero) 'hold down key 2
                System.Threading.Thread.Sleep(20) 'let the key register
                keybd_event(secondKey, 0, 2, UIntPtr.Zero) 'release key 2
                keybd_event(firstKey, 0, 2, UIntPtr.Zero) 'release key 1
            Catch ex As Exception
            End Try
        End Sub
    End Class
    Enjoy.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  2. The Following 3 Users Say Thank You to Jason For This Useful Post:

    FUKO (10-12-2011),[MPGH]master131 (10-12-2011),TimoTerremoto (10-12-2011)

  3. #2
    TimoTerremoto's Avatar
    Join Date
    Oct 2011
    Gender
    male
    Location
    Spain
    Posts
    4
    Reputation
    10
    Thanks
    0
    My Mood
    Dead

    Talking

    Hey Jason!

    I will attach it to my BOT class and 'hopefully' see if it works

    Thank you very much for sharing the code, I really appreciate it.
    Timo

  4. #3
    TimoTerremoto's Avatar
    Join Date
    Oct 2011
    Gender
    male
    Location
    Spain
    Posts
    4
    Reputation
    10
    Thanks
    0
    My Mood
    Dead
    Hello again,

    Since I cannot send you private messages I post my question here, sorry for the maybe little off-topic.

    I used your code and realized that I cannot include it the way I wanted, I just realized that keybd_event has no hWnd. The main reason I needed the code was for movement, since with my actual code can bot the game even if its not active (in background, NOT minimized, everything works except for movement) and it is based on PostMessage an SendMessage. The movement is somehow protected and it works well with keybd_event (your code) but it only works if the windows is active (selected). Man what a headache. hehe.

    EDIT: I may make a Form that shows up for 10 seconds advising, when certain task is done and movement is necessary, that says "the game is getting focused in 10 seconds, get ready and please don't touch anything until the character has arrived to his new position", once arrived at the new location, game is send back to background.

    If you have any suggestion, please let me know.

    Regards,
    Timo
    Last edited by TimoTerremoto; 10-12-2011 at 07:03 AM. Reason: Added information.

Similar Threads

  1. Ban ‘Hot Sauce'
    By Corndog in forum General
    Replies: 76
    Last Post: 09-25-2010, 05:25 AM
  2. Fail Sauce Production Hex Editing Applications
    By InCognito in forum Combat Arms Mod Discussion
    Replies: 53
    Last Post: 06-20-2010, 11:53 AM
  3. The great sauce debate
    By Synns in forum General
    Replies: 37
    Last Post: 05-17-2010, 08:47 PM
  4. holy tarter sauce i checked the price of mpgh
    By beteasta3 in forum General
    Replies: 33
    Last Post: 08-06-2009, 12:34 PM
  5. nub sauce is me
    By DeathScourge in forum General
    Replies: 8
    Last Post: 06-10-2009, 02:29 PM