Join us at IRC!
I'd prefer to die standing, than to live on my knees - Che Guevara
Friday, May 25, 2012
Navigation
Members Online
Total Online: 30
Web Spiders: 14
Guests Online: 29
Members Online: 1

Registered Members: 70209
Newest Member: KalareShou
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Python SendKeys Win32API

ctrl_
Member



Posts: 15
Location:
Joined: 11.02.09
Rank:
Wiseman
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:

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
Future Emperor of Earth



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




ynori7 http://halls-of-valhalla.org
Author

RE: Python SendKeys Win32API

reaper4334
Member



Posts: 314
Location: Uk
Joined: 24.11.06
Rank:
God
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]








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

RE: Python SendKeys Win32API

ynori7
Future Emperor of Earth



Posts: 1481
Location: #valhalla
Joined: 08.10.07
Rank:
Diabolical
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.




ynori7 http://halls-of-valhalla.org
Author

RE: Python SendKeys Win32API

ctrl_
Member



Posts: 15
Location:
Joined: 11.02.09
Rank:
Wiseman
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: 314
Location: Uk
Joined: 24.11.06
Rank:
God
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.

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

Just a rough idea








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

RE: Python SendKeys Win32API

ctrl_
Member



Posts: 15
Location:
Joined: 11.02.09
Rank:
Wiseman
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.
import win32api
import win32com.client

shell = win32com.client.Dispatch("Wscblockedript.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: 314
Location: Uk
Joined: 24.11.06
Rank:
God
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.
import win32api
import win32com.client

shell = win32com.client.Dispatch("Wscblockedript.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:
import win32api
import win32com.client

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

??






reaper4334@hotmail.co.uk http://reaper4334.freehostia.com
Author

RE: Python SendKeys Win32API

ctrl_
Member



Posts: 15
Location:
Joined: 11.02.09
Rank:
Wiseman
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: 314
Location: Uk
Joined: 24.11.06
Rank:
God
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?

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.






reaper4334@hotmail.co.uk http://reaper4334.freehostia.com
Author

RE: Python SendKeys Win32API

ctrl_
Member



Posts: 15
Location:
Joined: 11.02.09
Rank:
Wiseman
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:


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.
Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.