Jump to content


Photo

Ok killers another Question!


  • Please log in to reply
12 replies to this topic

#1 silentblood

silentblood
  • Members
  • 36 posts

Posted 20 June 2004 - 02:53 PM

Is it possible to send keystrokes to a specific program. For example, I play Shadowbane I duel log on one machine, could I write it into my script to only send keystrokes to just one client, so I could keep it minimized and play on other account. To do this I know for sure I will make two different directorys and name the Shadowbane EXEs to different names. I know it can be done just not sure hows it done with AHk.
Also great work on AHK guys this is a great free program better than some you have to pay for great works and keep it up. I am gonna be getting alot of the macroers on sb to start using this app.

Oh forgot to ask something is there anyway to hot key the scripts to activate on command. I think the answer would be to put a looping program that looks for certain keystroke then activates desired script name its directory is that close?

#2 silentblood

silentblood
  • Members
  • 36 posts

Posted 20 June 2004 - 04:18 PM

Ok I answermyself on the very last question +t:: would cause the sscript to launch when shift+t is keyed.

#3 Chris

Chris
  • Administrators
  • 10727 posts

Posted 20 June 2004 - 07:28 PM

Is it possible to send keystrokes to a specific program.

The first thing to try is ControlSend, in this order:
ControlSend, , text to send .... ; leave first param blank to send to topmost control.
ControlSend, ahk_parent, text to send ... ; Send directly to the parent window
(You'll need to fill in the other params for the above commands)

If neither of the above work, you can try using PostMessage as in this (working) example:
Run, wordpad
WinWait, Document -
WinActivate
ControlGetFocus, focused_control
start = 0
Loop 
{ 
   PostMessage, 0x102, %start%, 1, %focused_control%
   ++start 
   if start > 600
      break 
}
Some games are resistant to automation and might not work with any of the above methods. They might not even work with the Send command itself. All you can do is experiment.

Edit: Uses ControlFocus now since control names vary in different versions of WordPad.

#4 jamestr

jamestr
  • Members
  • 98 posts

Posted 21 June 2004 - 01:52 AM

if you have the same program running under 2 different names,
you shold be able to identify them using window ID.

http://www.autohotke...ands/WinGet.htm


^,::
WinGet, active_id, ID, A
WinGetClass, this_class, ahk_id %active_id%
WinGetTitle, this_title, ahk_id %active_id%
MsgBox, 0, , id - %active_id%`nclass - %this_class%`nName - %this_title%`n


#5 silentblood

silentblood
  • Members
  • 36 posts

Posted 25 June 2004 - 01:56 AM

Ok I am getting most things you guys are telling me. This is one that is not making much sense. Someone Show me example of sending keystrokes just to shadowbane. Its name is sb.exe. I need to be able to send keystrokes only it will recieve.

#6 Chris

Chris
  • Administrators
  • 10727 posts

Posted 25 June 2004 - 02:19 AM

The examples I gave above are the best ways I know how to do it (if it's possible at all with this particular game). You'll need to find out the title, class, or ID of the target window to use those examples. Most of that info can be discovered with Window Spy, which can be launched from the tray menu. If it's a full screen game, create a hotkey that runs WinGetClass and/or WinGetTitle when you press a hotkey and puts the text on the clipboard:

#z::WinGetClass, clipboard, A

Then press the hotkey while in the game, and the class name should now be on the clipboard.

If you have two windows that have the same title, text, and class, you'll need to get their IDs with WinGet as jamestr mentioned above.

Of course, you can also use the Send command to send keystrokes directly to the active window.

#7 silentblood

silentblood
  • Members
  • 36 posts

Posted 25 June 2004 - 05:02 AM

^,::
WinGet, active_id, ID, A
WinGetClass, this_class, ahk_id %active_id%
WinGetTitle, this_title, ahk_id %active_id%
MsgBox, 0, , id - %active_id%`nclass - %this_class%`nName - %this_title%`n



Ok I ran that and it gave me the following information

id-0x80050
class-opengl
name-shadowbane




Now I know this is proably a dumb question but what do I do with that information.

#8 beardboy

beardboy
  • Members
  • 443 posts

Posted 25 June 2004 - 05:52 AM

If you have two instances of shadowbane running you are going to have to decide which one to send the key strokes to. I have a script that ends up having two windows that are the same name and same class so I also had to seperate them by ID. Here is an example of how to send seperate key strokes to the different windows.

WinGet, windowlist, list, shadowbane ; Get list of shadowbane Window ID's
Loop, %windowlist%
{
  StringTrimRight, windowid, windowlist%a_index%, 0
  if a_index = 1
    ControlSend,, abc, ahk_id %windowid%; Send abc to first shadowbane window
  if a_index = 2
    ControlSend,, def, ahk_id %windowid%; Send def to second shadowbane window
}
thanks,
beardboy

#9 Chris

Chris
  • Administrators
  • 10727 posts

Posted 25 June 2004 - 11:52 AM

what do I do with that information

Experiment with these (the first was illustrated above by beardboy):
ControlSend, , text to send .... ; leave first param blank to send to topmost control.
ControlSend, ahk_parent, text to send ... ; Send directly to the parent window
(You'll need to fill in the other params for the above commands)

If neither of the above work, you can try using PostMessage as in this (working) example (see my earlier post above).

#10 silentblood

silentblood
  • Members
  • 36 posts

Posted 26 June 2004 - 09:53 PM

ControlSend,,%Stance% , Shadowbane



That is a copy of the command I am using now it does pretty much what I want it to using that. Only thing it did so far I didn't like was I was on the website called shadowbane and it froze my macro till I left the site. Any Ideas.

#11 jamestr

jamestr
  • Members
  • 98 posts

Posted 26 June 2004 - 11:34 PM

you want to distinguish between the website vs the game?

(both named shadowbane)?

you should be able to identify the website browser window and then use a ifwinactive command.

ifwinactive, Shadowbane -


the '-' makes the window unique

Posted Image

#12 silentblood

silentblood
  • Members
  • 36 posts

Posted 28 June 2004 - 03:37 AM

Ok I got it working just how I needed it to. Here is how I ended up doing it just for reference.


WinGet,SBID, ID,A

This is outside of my infinite loop in the top of my macro so it only checks once when you first start the macro. You must be in the the client you want to bind the macro to when you hotkey start the macro. It will then bind to the current SB Client windows ID number. You can then use the following to do direct input to the windows ID number.

ControlSend,,%CombatKey% , ahk_id %SBID%

This enters whatever the person has set as there combat key in the ini file and sends it to binded client. You can do as many client ahk binds as you want just got to do one at a time.

#13 jantzen05

jantzen05
  • Members
  • 8 posts

Posted 20 August 2004 - 11:37 AM

I am trying to make a macro like yours, is it possible that I could get yours?