Follow us on Twitter!
Hacking isn't just Computers & Exploits. It's a Philosophy. - Mr_Cheese
Saturday, April 19, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 31
Guests Online: 30
Members Online: 1

Registered Members: 82841
Newest Member: and3rv1sh
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Python SendKeys Win32API


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 11-05-09 16:56

I'am trying to send keystrokes to a program with Python, that part went well, but I'am having problem with holding/pressing the key down for a period of time.
A friend tiped me of thet this code works:

Code
shell.SendKeys("<KeyPress-w>") 
win32api.Sleep(5000)
shell.SendKeys("<KeyRelease-w>")




The problem is that it also sends the <KeyPress-w> to the app too.
Anyone know a solution for this?

Author

RE: Python SendKeys Win32API

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 11-05-09 17:16
What exactly are you trying to do? Why do you need to send keystrokes?


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: Python SendKeys Win32API

reaper4334
Member



Posts: 315
Location: Uk
Joined: 24.11.06
Rank:
Moderate
Posted on 11-05-09 17:30
What exactly are you trying to do?

[Edit]
Well, that's awkward having said the exact same thing as ynori.
His post wasn't there when I posted.
[/Edit]



i129.photobucket.com/albums/p210/reaper4334/reaper.png

www.catb.org/hacker-emblem/glider.png


Edited by reaper4334 on 11-05-09 17:31
reaper4334@hotmail.co.uk http://reaper4334.freehostia.com
Author

RE: Python SendKeys Win32API

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 11-05-09 18:45
reaper4334 wrote:
His post wasn't there when I posted.

That's hard to believe since I posted 15 minutes before you. You must type reeeeaaally slow.


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: Python SendKeys Win32API


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 11-05-09 19:14
I'am trying to tell a application that I'am holøding down a certain key, like moving around inside a game.
Author

RE: Python SendKeys Win32API

reaper4334
Member



Posts: 315
Location: Uk
Joined: 24.11.06
Rank:
Moderate
Posted on 11-05-09 20:42
ynori7 wrote:
reaper4334 wrote:
His post wasn't there when I posted.

That's hard to believe since I posted 15 minutes before you. You must type reeeeaaally slow.

haha I probably just opened the thread, got distracted, then came back and didn't refresh. Sorry lol

ctrl_ wrote:
I'am trying to tell a application that I'am holøding down a certain key, like moving around inside a game.

Errrr... Any more specifics?

[Edit]
You could try checking what the active window is and then using that.
Code

while someloop:
    if window="Internet Explorer":
        # send the key
    else:
        # don't
    if window != prev_window:
        prev_window = window
        break




Just a rough idea



i129.photobucket.com/albums/p210/reaper4334/reaper.png

www.catb.org/hacker-emblem/glider.png


Edited by reaper4334 on 11-05-09 20:45
reaper4334@hotmail.co.uk http://reaper4334.freehostia.com
Author

RE: Python SendKeys Win32API


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 12-05-09 19:36
What I'm trying to is to move a character of some sort inside a game by holding down the varius movement keys like W, A, S and D.
The problem so far is that I can't find a way to press/hold down the key for a period of time.
I have tryed the following code and it works, but the problem is that it sends everything inside the "" and not W, but it does work for some reason.
Code
import win32api
import win32com.client

shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate("Garry's Mod")
win32api.Sleep(100)
shell.SendKeys("<KeyPress-w>")
win32api.Sleep(5000)
shell.SendKeys("<KeyRelease-w>")





What I'm trying to find is a way to to that without sending all the other keys to the app to.

Author

RE: Python SendKeys Win32API

reaper4334
Member



Posts: 315
Location: Uk
Joined: 24.11.06
Rank:
Moderate
Posted on 13-05-09 16:56
ctrl_ wrote:
What I'm trying to is to move a character of some sort inside a game by holding down the varius movement keys like W, A, S and D.
The problem so far is that I can't find a way to press/hold down the key for a period of time.
I have tryed the following code and it works, but the problem is that it sends everything inside the "" and not W, but it does work for some reason.
Code
import win32api
import win32com.client

shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate("Garry's Mod")
win32api.Sleep(100)
shell.SendKeys("<KeyPress-w>")
win32api.Sleep(5000)
shell.SendKeys("<KeyRelease-w>")





What I'm trying to find is a way to to that without sending all the other keys to the app to.


You mean it sends "<KeyPress-w>"?

If so, have you tried:
Code
import win32api
import win32com.client

shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate("Garry's Mod")
win32api.Sleep(100)
shell.SendKeys("w")
win32api.Sleep(5000)
shell.SendKeys("w")




??



i129.photobucket.com/albums/p210/reaper4334/reaper.png

www.catb.org/hacker-emblem/glider.png
reaper4334@hotmail.co.uk http://reaper4334.freehostia.com
Author

RE: Python SendKeys Win32API


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 13-05-09 18:40
Then it just sends the "w" once and waits 5 sec before it sends another. With the <KeyPress-w> and <KeyRelease-w> it does hold down the key but it also sends the K-e-y-P-r-e-s-s.
Author

RE: Python SendKeys Win32API

reaper4334
Member



Posts: 315
Location: Uk
Joined: 24.11.06
Rank:
Moderate
Posted on 13-05-09 18:48
ctrl_ wrote:
Then it just sends the "w" once and waits 5 sec before it sends another. With the <KeyPress-w> and <KeyRelease-w> it does hold down the key but it also sends the K-e-y-P-r-e-s-s.


Hmm.. in that case, have you checked to see if "KeyPress" and "KeyRelease" have their own functions rather than being used in "SendKeys"? That's all I can really think of.

Have you tried doing a loop?

Code
import win32api
import win32com.client

shell = win32com.client.Dispatch("Wscblockedript.Shell")
shell.AppActivate("Garry's Mod")
i = 0
while i <= 5000:
    shell.SendKeys("w")
    win32api.Sleep(10)
    i += 10




I doubt that'l work, though, if it's being used in a game.. it'l probably end up walking, stopping, walking, stopping.. etc.. but it's worth a try.



i129.photobucket.com/albums/p210/reaper4334/reaper.png

www.catb.org/hacker-emblem/glider.png
reaper4334@hotmail.co.uk http://reaper4334.freehostia.com
Author

RE: Python SendKeys Win32API


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 15-05-09 13:38
I have checked if they got owne functions but I was only able to find some for linux and not windows.


reaper4334 wrote:


Code
import win32api
import win32com.client

shell = win32com.client.Dispatch("Wscblockedript.Shell")
shell.AppActivate("Garry's Mod")
i = 0
while i <= 5000:
    shell.SendKeys("w")
    win32api.Sleep(10)
    i += 10





I have also tryed this with poor results.