quickly fix my problem?

Get help with using AutoHotkey and its commands and hotkeys
fixiie
Posts: 23
Joined: 16 Apr 2017, 18:03

quickly fix my problem?

11 May 2017, 09:21

I'm missing something, but im not sure why.

Code: Select all

#Persistent
Process, Close, antimicro.exe
Run, C:\Program Files (x86)\Mozilla Firefox\firefox.exe
Run, X:\Emulator\- AntiMicro\Sets\8.exe
While (!WinExist("ahk_exe firefox.exe"))
	Continue
Sleep 1500
MouseClick, left, 942, 807, 1
Send, {F11}
CheckProgram:
IF (!WinExist("ahk_exe firefox.exe")) { ; IF the application is not running
	Sleep 1000
	Process, Close, antimicro.exe
	ExitApp
}
return
The script is persitent and is still up after everything is run, but whenever firefox.exe closes it doesn't read whats inside "checkprogram".



thanks :)
BoBo
Posts: 3755
Joined: 13 May 2014, 17:15

Re: quickly fix my problem?

11 May 2017, 10:06

Code: Select all

#Persistent
Process, Close, antimicro.exe
Run, C:\Program Files (x86)\Mozilla Firefox\firefox.exe
Run, X:\Emulator\- AntiMicro\Sets\8.exe
While (!WinExist("ahk_exe firefox.exe")) ; IF the application is not running
	Continue ; let's wait for FF
Sleep 1500 ; OK FF has obviously appeared
MouseClick, left, 942, 807, 1 ; let's click a little
Send, {F11} ; probably fullscreen mode ?
CheckProgram: ; let's guess FF is still alive
IF (!WinExist("ahk_exe firefox.exe")) { ; now we check ONCE if FF is NOT alive which is false, so ...
	Sleep 1000 ; ignore ...
	Process, Close, antimicro.exe ; the ...
	ExitApp ; rest
}
return
Correct me if I'm wrong :)
What about a Loop or better SetTimer-routine to check for FF's status ???
fixiie
Posts: 23
Joined: 16 Apr 2017, 18:03

Re: quickly fix my problem?

11 May 2017, 10:15

BoBo wrote:

Code: Select all

#Persistent
Process, Close, antimicro.exe
Run, C:\Program Files (x86)\Mozilla Firefox\firefox.exe
Run, X:\Emulator\- AntiMicro\Sets\8.exe
While (!WinExist("ahk_exe firefox.exe")) ; IF the application is not running
	Continue ; let's wait for FF
Sleep 1500 ; OK FF has obviously appeared
MouseClick, left, 942, 807, 1 ; let's click a little
Send, {F11} ; probably fullscreen mode ?
CheckProgram: ; let's guess FF is still alive
IF (!WinExist("ahk_exe firefox.exe")) { ; now we check ONCE if FF is NOT alive which is false, so ...
	Sleep 1000 ; ignore ...
	Process, Close, antimicro.exe ; the ...
	ExitApp ; rest
}
return
Correct me if I'm wrong :)
What about a Loop or better SetTimer-routine to check for FF's status ???
i like the comments :)

I tested loop bit but never used it so i never got it to work, but yeah i think loop could do it. how would i go around doing this?
BoBo
Posts: 3755
Joined: 13 May 2014, 17:15

Re: quickly fix my problem?

11 May 2017, 10:41

Code: Select all

#SingleInstance, Force

Width := 1200 ; change this to your liking/desktop resolution  ! 
Height := 800

Process, Close, antimicro.exe
Run, C:\Program Files (x86)\Mozilla Firefox\firefox.exe -height %Height% -width %Width% ; to start FF with specified mode eg fullscreen
Run, X:\Emulator\- AntiMicro\Sets\8.exe

While (WinExist("ahk_exe firefox.exe")) { ; now we check if FF still EXISTS
	Continue
Process, Close, antimicro.exe
ExitApp
return
Hell, While is your Loop :thumbup:
fixiie
Posts: 23
Joined: 16 Apr 2017, 18:03

Re: quickly fix my problem?

11 May 2017, 10:49

BoBo wrote:

Code: Select all

#SingleInstance, Force

Width := 1200 ; change this to your liking/desktop resolution  ! 
Height := 800

Process, Close, antimicro.exe
Run, C:\Program Files (x86)\Mozilla Firefox\firefox.exe -height %Height% -width %Width% ; to start FF with specified mode eg fullscreen
Run, X:\Emulator\- AntiMicro\Sets\8.exe

While (WinExist("ahk_exe firefox.exe")) { ; now we check if FF still EXISTS
	Continue
Process, Close, antimicro.exe
ExitApp
return
Hell, While is your Loop :thumbup:
Doesn't work, same issue (antimicro doesn't close when firefox does) & now the script exe dissappears before firefox exe closes from taskmanager (maybe intentional i guess), also the fullscreen doesn't really work either :P
BoBo
Posts: 3755
Joined: 13 May 2014, 17:15

Re: quickly fix my problem?

12 May 2017, 06:55

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance, Force
SetTitleMatchMode, 2 

Process(Name,cmd){
	Process,% cmd, % Name
	Return Errorlevel
	}

F12::												; press F12
   WinGetPos, X, Y, Width, Height, Program Manager	; your desktops scale
   ; Process("antimicro.exe","Close")				; Leave this for U!
   Run, firefox.exe "http://www.google.com",, Max	; Calling FF
   Process("firefox.exe","Wait")					; just out of curiosity
   ; Run, X:\Emulator\- AntiMicro\Sets\8.exe		; see above
   WinWaitActive, Mozilla Firefox
   MouseClick, left,% Width/2,% Height/2, 1			; clickin right in the center of your screen
   Sleep, 100										; power napping
   Send {F11}										; manually triggering kiosk-mode, not that reliable see line above
   While (!Process("firefox.exe","Exist"))			; is FF alive ? (I've tested this using the old fashioned "Loop" + If !Process( ...). Let's get fingers crossed
    	Break
   SoundBeep										; FF has died already and therefore we ring that tiny obsolete bell
   ; Process("antimicro.exe","Close")				; kill that other b...
   Return
    
fixiie
Posts: 23
Joined: 16 Apr 2017, 18:03

Re: quickly fix my problem?

12 May 2017, 13:09

BoBo wrote:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance, Force
SetTitleMatchMode, 2 

Process(Name,cmd){
	Process,% cmd, % Name
	Return Errorlevel
	}

F12::												; press F12
   WinGetPos, X, Y, Width, Height, Program Manager	; your desktops scale
   ; Process("antimicro.exe","Close")				; Leave this for U!
   Run, firefox.exe "http://www.google.com",, Max	; Calling FF
   Process("firefox.exe","Wait")					; just out of curiosity
   ; Run, X:\Emulator\- AntiMicro\Sets\8.exe		; see above
   WinWaitActive, Mozilla Firefox
   MouseClick, left,% Width/2,% Height/2, 1			; clickin right in the center of your screen
   Sleep, 100										; power napping
   Send {F11}										; manually triggering kiosk-mode, not that reliable see line above
   While (!Process("firefox.exe","Exist"))			; is FF alive ? (I've tested this using the old fashioned "Loop" + If !Process( ...). Let's get fingers crossed
    	Break
   SoundBeep										; FF has died already and therefore we ring that tiny obsolete bell
   ; Process("antimicro.exe","Close")				; kill that other b...
   Return
    

it seems..... good, but what is it i should change in the script?

Is the starting dir for mozilla firefox or the script?

other than that the fullscreen works, but unfortunatly the script just beeps abit after f12 is pressed, which means it terminates 'antimicro' before firefox closes. =/


this is how it looks after change:

Code: Select all

#NoEnv 																	 ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input															 ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  										 	 ; Ensures a consistent starting directory.

#SingleInstance, Force
SetTitleMatchMode, 2 

Process(Name,cmd){
	Process,% cmd, % Name
	Return Errorlevel
	}

F12::																	 ; press F12
   WinGetPos, X, Y, Width, Height, Program Manager						 ; your desktops scale
   Process("antimicro.exe","Close")									 	 ; Leave this for U!
   Run, C:\Program Files (x86)\Mozilla Firefox\firefox.exe,, Max		 ; Calling FF
   Process("firefox.exe","Wait")										 ; just out of curiosity
   Run, X:\Emulator\- AntiMicro\Sets\8.exe							 	 ; see above
   WinWaitActive, Mozilla Firefox
   MouseClick, left,% Width/2,% Height/2, 1								 ; clickin right in the center of your screen
   Sleep, 100															 ; power napping
   Send {F11}															 ; manually triggering kiosk-mode, not that reliable see line above
   While (!Process("firefox.exe","Exist"))								 ; is FF alive ? (I've tested this using the old fashioned "Loop" + If !Process( ...). Let's get fingers crossed
    	Break
   SoundBeep															 ; FF has died already and therefore we ring that tiny obsolete bell
   Process("antimicro.exe","Close")										 ; kill that other b...
   Return
fixiie
Posts: 23
Joined: 16 Apr 2017, 18:03

Re: quickly fix my problem?

14 May 2017, 11:57

help somebody plx, this is my last big script i need :F
pneumatic
Posts: 299
Joined: 05 Dec 2016, 01:51

Re: quickly fix my problem?

14 May 2017, 17:00

Put #Persistent back at the top, then run it and right click the tray Icon and Open and F5 to refresh so you can see what lines of code got executed and that should tell you what's happening.

Here I have added 2 lines to your original code in post #1, and to me it looks like it should work, but in reality things never do work so you'll always have to test and debug to see what's really happening at runtime.

Code: Select all

#Persistent
Process, Close, antimicro.exe
Run, C:\Program Files (x86)\Mozilla Firefox\firefox.exe
Run, X:\Emulator\- AntiMicro\Sets\8.exe
While (!WinExist("ahk_exe firefox.exe"))            
	Continue
Sleep 1500
MouseClick, left, 942, 807, 1
Send, {F11}
SetTimer, CheckProgram, 250
return
CheckProgram:
IF (!WinExist("ahk_exe firefox.exe")) { ; IF the application is not running
	Sleep 1000
	Process, Close, antimicro.exe
	ExitApp
}
return
fixiie
Posts: 23
Joined: 16 Apr 2017, 18:03

Re: quickly fix my problem?

14 May 2017, 20:46

pneumatic wrote:Put #Persistent back at the top, then run it and right click the tray Icon and Open and F5 to refresh so you can see what lines of code got executed and that should tell you what's happening.

Here I have added 2 lines to your original code in post #1, and to me it looks like it should work, but in reality things never do work so you'll always have to test and debug to see what's really happening at runtime.

Code: Select all

#Persistent
Process, Close, antimicro.exe
Run, C:\Program Files (x86)\Mozilla Firefox\firefox.exe
Run, X:\Emulator\- AntiMicro\Sets\8.exe
While (!WinExist("ahk_exe firefox.exe"))            
	Continue
Sleep 1500
MouseClick, left, 942, 807, 1
Send, {F11}
SetTimer, CheckProgram, 250
return
CheckProgram:
IF (!WinExist("ahk_exe firefox.exe")) { ; IF the application is not running
	Sleep 1000
	Process, Close, antimicro.exe
	ExitApp
}
return
thankyouthankyouthankyouthankyou!

finally it works perfectly :D - one last thing though since it just came to mind.

I tried creating it myself but for some reason it just didnt work.

Can you quickly create a working if else for this (check bottom after the "LCtrl & L::"):

Code: Select all

#Persistent
Process, Close, Photoshop.exe
Process, Close, antimicro.exe
Run, C:\Program Files\Adobe\Adobe Photoshop CC 2017\Photoshop.exe,, max
Run, X:\Emulator\- AntiMicro\Sets\8.exe
While (!WinExist("ahk_exe Photoshop.exe"))            
	Continue
Sleep 1500
MouseClick, left, 942, 807, 1
Send, {F11}
SetTimer, CheckProgram, 250
return
CheckProgram:
IF (!WinExist("ahk_exe Photoshop.exe")) { ; IF the application is not running
	Sleep 1000
	Process, Close, antimicro.exe
	ExitApp
}
return

LCtrl & L::
	if "osk.exe is running", run this:
Process, Close, osk.exe
	else Run, c:\blablabla\osk.exe

- sorry for begging like this, hours of trying to get various scripts working can get very frusterating when you're new to this stuff.

huge thanks again!


EDIT: also i just noticed, while hotkeys (for example ESC) is used as a hotkey within the script and it's enabled, they become exclusive to the script making it impossible to use them for other programs meanwhile the script is up.
With other words i can't press esc while in firefox since it will only affect the script & nothing else. any fix for it to work for both?
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: quickly fix my problem?

14 May 2017, 21:53

See the Documentation about Process, Close:
Since the process will be abruptly terminated -- possibly interrupting its work at a critical point or resulting in the loss of unsaved data in its windows (if it has any) -- this method should be used only if a process cannot be closed by using WinClose on one of its windows.

Code: Select all

<^l::
Process, Exist, osk.exe
if (ErrorLevel) { ; set and eveluated to true if the matching process exists
; Process, Close, osk.exe ; the forcefull way
PostMessage, 0x112, 0xF060,,, ahk_exe osk.exe ; similar to pressing Alt-F4 or clicking the window's close button
} else {
Run, c:\blablabla\osk.exe
}
return
fixiie wrote: (...)also i just noticed, while hotkeys (for example ESC) is used as a hotkey within the script and it's enabled, they become exclusive to the script making it impossible to use them for other programs meanwhile the script is up. (...)
See the documentation about the tilde (~) operator.
my scripts
fixiie
Posts: 23
Joined: 16 Apr 2017, 18:03

Re: quickly fix my problem?

18 May 2017, 19:24

A_AhkUser wrote:See the Documentation about Process, Close:
Since the process will be abruptly terminated -- possibly interrupting its work at a critical point or resulting in the loss of unsaved data in its windows (if it has any) -- this method should be used only if a process cannot be closed by using WinClose on one of its windows.

Code: Select all

<^l::
Process, Exist, osk.exe
if (ErrorLevel) { ; set and eveluated to true if the matching process exists
; Process, Close, osk.exe ; the forcefull way
PostMessage, 0x112, 0xF060,,, ahk_exe osk.exe ; similar to pressing Alt-F4 or clicking the window's close button
} else {
Run, c:\blablabla\osk.exe
}
return
fixiie wrote: (...)also i just noticed, while hotkeys (for example ESC) is used as a hotkey within the script and it's enabled, they become exclusive to the script making it impossible to use them for other programs meanwhile the script is up. (...)
See the documentation about the tilde (~) operator.
Flawless, perfect.. Thank you!

One last note before i go which i couldn't find much about on google - Is there a way to make exe open AT your cursor. In this case i'm talking about the Osk.exe aka On Screen Keyboard for windows.
I googled around and found WinMove, which i assume is the best for this case and also you can create a simple variable for the mouse coords using this:

Code: Select all

CoordMode, Mouse, Screen
Check: 
MouseGetPos, xx, yy
but i don't really know how to write it all up into one, and where exactly it should be written.

This is the full code right now (After the last 'else' is where the WinMove should be):

Code: Select all

#Persistent
Process, Close, firefox.exe
Process, Close, antimicro.exe
Run, C:\Program Files (x86)\Mozilla Firefox\firefox.exe
Run, X:\Emulator\- AntiMicro\Sets\8.exe
While (!WinExist("ahk_exe firefox.exe"))            
	Continue
Sleep 1500
MouseClick, left, 942, 807, 1
Send, {F11}
SetTimer, CheckProgram, 250
return
CheckProgram:
IF (!WinExist("ahk_exe firefox.exe")) { ; IF the application is not running
	Sleep 1000
	Process, Close, antimicro.exe
	ExitApp
}
return

LCtrl & L::

Process, Exist, osk.exe
if (ErrorLevel) { ; set and eveluated to true if the matching process exists
; Process, Close, osk.exe ; the forcefull way
PostMessage, 0x112, 0xF060,,, ahk_exe osk.exe ; similar to pressing Alt-F4 or clicking the window's close button
} else {
Run, C:\Windows\System32\osk.exe
}
return
	

~Enter & Backspace::
	Process, Close, firefox.exe
	Process, Close, osk.exe
return
tyvm in advance!

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, DanRim, DMDComposer, f1ster, Google [Bot], Gushou, kjmcneil, Lecso0522, mikeyww, mmmax, TAC109 and 51 guests