only one window

Get help with using AutoHotkey and its commands and hotkeys
Alexey
Posts: 7
Joined: 18 Jun 2014, 15:09

only one window

10 Sep 2014, 02:19

I have a question on which I can't find the answer оn a forum and in the help pulover's.

Code: Select all

WinActivate, Last Chaos - Mail.ru (Window 1024x768)
Sleep, 333
Loop
{
	Send, {Tab}
	Sleep, 1000
	Send, {F7}
	Sleep, 1
	Send, {F2}
	Sleep, 1
	Send, {1}
	Sleep, 1
	Send, {3}
	Sleep, 2000
	Send, {Tab}
	Sleep, 1000
	Send, {1}
	Sleep, 1
	Sleep, 1000
	Send, {F6}
	Sleep, 1
	Sleep, 1000
	Click, 55, 71, 0
	Sleep, 10
	Click, Left, 1
	Sleep, 1000
	Click, 745, 680, 0
	Send, {7}
	Sleep, 1
	Sleep, 1000
}

As you can see a script is used in game, I don't understand as to make so that a script worked only in a game window.
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: only one window

10 Sep 2014, 08:59

Code: Select all

;#IfWinActive Last Chaos - Mail.ru (Window 1024x768)

; press F10 - ahkscript.org/docs/Hotkeys.htm
F10::
    ; replace MouseMove command with the loop in your first post and its contents
    MouseMove, 200, 200, , R
return
Alexey
Posts: 7
Joined: 18 Jun 2014, 15:09

Re: only one window

10 Sep 2014, 14:19

I want to work at the computer and that the script in game would work at this time.
I didn't understand than your script will help?
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: only one window

10 Sep 2014, 15:15

Sorry, thought that the script needs to be triggered from inside of the game and just 'run' there.

Perhaps use ControlSend/ControlClick instead of Send/Click. From my personal experience, it's hard to create a script that sends keystrokes to a given window and at the same time make that script not to interfere with what the user is 'normally' doing on the PC. One would rather do this through a virtual machine.
User avatar
RobertL
Posts: 540
Joined: 18 Jan 2014, 01:14
Location: China

Re: only one window

12 Sep 2014, 00:50

I was wondering if we can operate Mouse backstage/background by posting message (such like, WM_NCMOUSEMOVE/WM_NCLBUTTONDOWN/..) directly to the target window?
Just a guesswork without test nor search. If it is possible, then it would be easy to package to a Lib/Module.

BTW, the subject name 'only one window' is hard to understand!
我为人人,人人为己?
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: only one window

12 Sep 2014, 05:08

RobertL yes, internally, ControlClick sends Windows Messages.

So another method would be to use PostMessage or SendMessage with the appropriate message.
trismarck wrote:It's hard to create a script that sends keystrokes to a given window and at the same time make that script not to interfere with what the user is 'normally' doing on the PC.
After testing, this is false at least in the context of sending keys/clicks to a non-active window with standard Windows controls:

Code: Select all

hwndOld := WinActive("A")
Run, notepad, , , pid
WinWaitActive, ahk_pid %pid%
hwnd := WinExist()
WinSet, AlwaysOnTop, Toggle, ahk_id %hwnd%
WinActivate, ahk_id %hwndOld%
msgbox close msgbox and press and hold a key outside of notepad
sleep 5000
ControlSend, , aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, ahk_id %hwnd%
sleep 3000
WinClose, ahk_id %hwnd%
return
User avatar
RobertL
Posts: 540
Joined: 18 Jan 2014, 01:14
Location: China

Re: only one window

12 Sep 2014, 05:45

Good news!
Means using ControlSend / ControlClick is possible, and I read its documents roughly, there's little limit mentioned.
Thanks for your test, it's clear and obvious.
Last edited by RobertL on 13 Sep 2014, 23:49, edited 1 time in total.
我为人人,人人为己?
Alexey
Posts: 7
Joined: 18 Jun 2014, 15:09

Re: only one window

13 Sep 2014, 23:48

Sorry, probable I not programmer,
but I don't understand how to make so that the example given by you worked for me in a script
User avatar
RobertL
Posts: 540
Joined: 18 Jan 2014, 01:14
Location: China

Re: only one window

14 Sep 2014, 00:02

Change Send / Click to ControlSend / ControlClick, consider other parameters in ControlXXX.
Like ControlSend ,,{Tab},Last Chaos - Mail.ru, ControlClick ,X50 Y71,Last Chaos - Mail.ru,,Left.
Not tested, you need to fill in the parameters in a appropriate position.
Read the document of these two function first, then you got ability to apply arbitrarily.
我为人人,人人为己?
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: only one window

14 Sep 2014, 04:13

For ControlSend, use Active Window Info to obtain the ClassNN of the _control_ (if keys won't work straight away after sending them to the _window_). WinList can also list all controls of the window.
Image
User avatar
RobertL
Posts: 540
Joined: 18 Jan 2014, 01:14
Location: China

Re: only one window

14 Sep 2014, 04:50

From his code I think just omitted Control of ControlSend/Click so just Send to the target window's topmost control.
Get more control to the control would be nice.

BTW @trismarck , is _x_ a markdown syntax for emphasizing?
我为人人,人人为己?
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: only one window

14 Sep 2014, 05:52

RobertL wrote:From his code I think just omitted Control of ControlSend/Click so just Send to the target window's topmost control.
Yes.
RobertL wrote:BTW @trismarck , is _x_ a markdown syntax for emphasizing?
Yes, I just do it because [ i ] is sometimes not visible enough.

Return to “Ask For Help”

Who is online

Users browsing this forum: brotherS, calipsoive, Google [Bot], KiddoV, malcev, Rohwedder, tobsto occupied, vsub, Yakshongas and 98 guests