(Help) sned key to application

Posts 1–15 of 17 · Page 1 of 2
(Help) sned key to application
title says it i can seem to get it to work

Im trying to send numpad9 to process game
sendkeys.send("numpad9")
i also have this in a loop but it wont send it to the game
im trying to put it on a button click so when its pushed it presses that button until stopped
Do you want to do it without having it focused, or doesn't that matter?

If it doesn't matter use the Keyboard Api nextgen posted (SDK sticky)
ok that made things worse so heres what im dealing with now i can sendkeys to the program in game when i open the chat box it spams it with what ever key i program it to send.

But what im trying to do is use the games built in shortcuts to make a trainer bot yea it spams the number or letter but the input is not recognized any suggestions
Quote Originally Posted by Maniac101 View Post
ok that made things worse so heres what im dealing with now i can sendkeys to the program in game when i open the chat box it spams it with what ever key i program it to send.

But what im trying to do is use the games built in shortcuts to make a trainer bot yea it spams the number or letter but the input is not recognized any suggestions
SendKeys won't for this because you're sending the key as a string not as an actual key value.

i.e
[php]
SendKeys.SendWait("S")
[/php]

Does not actually send the keydown/keyup of the letter S, it simply send the string "S" which is different.

keybd_event works nicely for this.

Add this declaration:

[php]
Public Declare Function keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) As Long

Const KEYEVENTF_KEYUP = &H2
[/php]

Okay here's two subs I wrote for something just like this.

[php]
Private Sub PressKey(ByVal mykey As Integer, ByVal PauseTime As Integer)

keybd_event(mykey, 0, 0, 0)
System.Threading.Thread.Sleep(PauseTime)
keybd_event(mykey, 0, KEYEVENTF_KEYUP, 0)

End Sub

[/php]

[php]
Private Sub SendString(ByVal WhatToSend As String)

Dim i As Integer = 0
Dim kcon As New KeysConverter

Do Until i = WhatToSend.Length
PressKey(kcon.ConvertFromString(WhatToSend(i)), 20)
i += 1
Loop
End Sub
[/php]

Okay I just wrote them then so at the moment the "SendString" doesn't allow spaces in the string (it just won't press space) but I'm working on tweaking it right now so hopefully i find a patchup for it, until then you can only send spaceless string :S but if you're working on hotkeys that should be enough for now.

Oh yeah, examples

Single key press:
[php]
PressKey(Keys.A, 20) 'this will press the "A" key down for 20ms
[/php]

Sending String:
[php]
SendString("awesome", 0) 'this will type in "awesome" pretty much instantaneously, adjust the speed if you want to get a realistic typing effect.
[/php]

Enjoy, i'll post here if i find the quickfix for spaces.

EDIT.


Fixed spaces, dunno why the hell VK doesn't understand wtf a space is, but nevertheless. Here's the fix for the SendString sub (thanks Hassan for the Char.IsWhiteSpace <3)

[php]
Private Sub SendString(ByVal WhatToSend As String, ByVal Pause As Integer)

Dim i As Integer = 0
Dim kcon As New KeysConverter

Do Until i = WhatToSend.Length

If Char.IsWhiteSpace(WhatToSend(i)) Then
PressKey(Keys.Space, pause)
Else
PressKey(kcon.ConvertFromString(WhatToSend(i)), Pause)
End If
i += 1
Loop

End Sub
[/php]

EXAMPLE:

[php]
SendString("I Love JDeezy")
[/php]

Just remember that VK doesn't work for symbols.

Good luck.
ok heres what i got when i used this

A call to PInvoke function 'shaiya trainer!WindowsApplication1.Form1::keybd_event' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Code:
Public Declare Function keybd_event Lib "user32" (ByVal bVK As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) As Long

    Const KEYEVENTF_KEYUP = &H2

    Private Sub PressKey(ByVal mykey As Integer, ByVal PauseTime As Integer)

        keybd_event(mykey, 0, 0, 0) ' this is where it calls the error at 
        System.Threading.Thread.Sleep(PauseTime)
        keybd_event(mykey, 0, KEYEVENTF_KEYUP, 0)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        PressKey(Keys.NumPad9, 1000)
        System.Threading.Thread.Sleep(1000)
        PressKey(Keys.NumPad9, KEYEVENTF_KEYUP)
    End Sub
Quote Originally Posted by Maniac101 View Post
ok heres what i got when i used this

Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        PressKey(Keys.NumPad9, KEYEVENTF_KEYUP)
    End Sub
Here's your problem. PressKey only accepts two parameters: a) the key you want to send, so that's correct. b) the length of time you want to hold the key down, this is the problem. You want to hold the key down for "KEYEVENTF_KEYUP" ms? Change this to an integer value.

Also, remove

Code:
        PressKey(Keys.NumPad9, 1000)
        System.Threading.Thread.Sleep(1000)
So in the end your click sub should just look like this:

[php]
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PressKey(Keys.NumPad9, 200) 'change the 200 ms to however long you want to hold the key down.
End Sub
[/php]

If you have any question, just ask.
Low Level Hooks
Just one thing J-Deezy instead of using KeysConverter, if you use VkKeyScan(), it will detect basically everything.. spaces, etc..
ok fixed my sub but its still calling the error on the
Private sub Presskey
Code:
Private Sub PressKey(ByVal mykey As Integer, ByVal PauseTime As Integer)

        keybd_event(mykey, 0, 0, 0) ' this is where it calls the error at says unbalanced stack
        System.Threading.Thread.Sleep(PauseTime)
        keybd_event(mykey, 0, KEYEVENTF_KEYUP, 0)
damn i wish i could thank you more then once LOL you been a big help
Quote Originally Posted by 'Bruno View Post
Just one thing J-Deezy instead of using KeysConverter, if you use VkKeyScan(), it will detect basically everything.. spaces, etc..
VkKeyScan requires an additional declaration which I couldn't be bothered finding. I'll change it if it makes you happy.
Quote Originally Posted by Jason View Post


VkKeyScan requires an additional declaration which I couldn't be bothered finding, also it kept fucking up for me so I gave up and went with KeysConverter
all it needs is a char man it's simpler than it looks like
Quote Originally Posted by 'Bruno View Post
all it needs is a char man it's simpler than it looks like
VB.NET requires the VkKeyScan declaration.

Fine, just because you want it

[php]
Public Declare Function keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) As Long
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal yourchar As Char) As Integer
Const KEYEVENTF_KEYUP = &H2
[/php]

[php]
Private Sub PressKey(ByVal mykey As Integer, ByVal PauseTime As Integer)

keybd_event(mykey, 0, 0, 0)
System.Threading.Thread.Sleep(PauseTime)
keybd_event(mykey, 0, KEYEVENTF_KEYUP, 0)

End Sub
[/php]

[php]
Private Sub SendString2(ByVal WhatToSend As String, ByVal PauseLength As Integer)

Dim strToSend As String = WhatToSend.ToLower
Dim i As Integer = 0

Do Until i = WhatToSend.Length
Press(VkKeyScane(strToSend(i)), pauselength)
i += 1
Loop

End Sub
[/php]

Nigga please.
lol now i got 2 ppl fighting over code thats great jk
anyhow any idea why im getting unbalanced stack in the first sub
Quote Originally Posted by Maniac101 View Post
lol now i got 2 ppl fighting over code thats great jk
anyhow any idea why im getting unbalanced stack in the first sub
no one is fighting

@J-Deezy:

See.. it looks better ^^ less problems.. and including one more declaration.. That's not a big deal
Btw i was just giving you an tip that would fix those problems ^^
Quote Originally Posted by Maniac101 View Post
lol now i got 2 ppl fighting over code thats great jk
anyhow any idea why im getting unbalanced stack in the first sub
I already posted why you're getting an unbalanced stack. Use my second snippet (the one in reply to Brinuz :P)

Yes Brinuz, but it also requires me to add a ".ToLower", these things take time

If you're still having troubles, TV again? lol
Posts 1–15 of 17 · Page 1 of 2
This thread is closed for replies.

Tags for this Thread

None

Talk with us