I am running the below script which opens an image when the user right-clicks, places it where he clicked, then closes the image after 10 seconds. I would like the user to be able to open the image multiple times, but the RButton hotkey is not responsive while the script is running (while it is sleeping supposedly). Is there something I can change that will allow me to open multiple images at the same time using the RButton?
RButton::
MouseGetPos, X, Y
Run "C:\Program Files (x86)\IrfanView\i_view32.exe" "C:\smile.png"
WinWait, smile
WinMove, X, Y
Sleep 10000
WinClose smile
Reload
Also, I added the "Reload" at the end of the script because for some reason the RButton would stop working even after the script completed. Adding Reload seemed to help fix this, but the RButton hotkey still sporadically does not work. Any advice you can give on this problem is also much appreciated.
Thanks!
how to allow multiple instances of a hotkey script
Started by
ahk_rocks
, Jan 06 2012 12:13 PM
6 replies to this topic
#1
-
Posted 06 January 2012 - 12:13 PM
Sets the maximum number of simultaneous threads per hotkey or hotstring.
Source: http://www.autohotke...dsPerHotkey.htm
#2
-
Posted 06 January 2012 - 12:24 PM
Thank you sir!
My next problem is that with multiple "smile.png" images open I need to find a way to manage the image windows using something other than the title. I haven't started to look yet but is there a way to grab the window ID of the image opened in a particular instance of the script?
My next problem is that with multiple "smile.png" images open I need to find a way to manage the image windows using something other than the title. I haven't started to look yet but is there a way to grab the window ID of the image opened in a particular instance of the script?
#3
-
Posted 06 January 2012 - 12:31 PM
Look at
and you can try to get the the PIDRuns an external program.
Source: http://www.autohotke...ommands/Run.htm
#4
-
Posted 06 January 2012 - 12:36 PM
Thank you again! What a supportive community! I found that processID parameter just as you posted. I should have looked first before posting.
#5
-
Posted 06 January 2012 - 12:38 PM
Ok so my script now looks like this:
#MaxThreadsPerHotkey 10
RButton::
MouseGetPos, X, Y
Run "C:\Program Files (x86)\IrfanView\i_view32.exe" "C:\smile.png", , , P
WinMove, ahk_pid %P%, , X, Y
Sleep 8000
WinClose, ahk_pid %P%
It all works as planned except only the last image window is closed if I open more than one image window at once. I suspect this is because the process ID variable P is being shared between all instances of the script. Is there a way to have a thread-specific variable to store each thread's process ID, so that I can use that variable to close the window after the sleep delay?
#MaxThreadsPerHotkey 10
RButton::
MouseGetPos, X, Y
Run "C:\Program Files (x86)\IrfanView\i_view32.exe" "C:\smile.png", , , P
WinMove, ahk_pid %P%, , X, Y
Sleep 8000
WinClose, ahk_pid %P%
It all works as planned except only the last image window is closed if I open more than one image window at once. I suspect this is because the process ID variable P is being shared between all instances of the script. Is there a way to have a thread-specific variable to store each thread's process ID, so that I can use that variable to close the window after the sleep delay?
#6
-
Posted 06 January 2012 - 01:10 PM
Here is a working script that supports 10 images.
It a a poor design and has a few flaws.
The design is poor because of the requirement for the routine r1, r2...
It has a flaw, because the windows a closed in reverse order.
By simply extending the original design, the first use of the hotkey is interrupted by the 2nd and latter uses.
so the windows are opened 1,2,3...10 and closed 10,9,8... 1
I may come up with a better version, but not at this moment.
BTW, did you know that AHk can display some image formats directly, without the need for irfanview.exe ?
It a a poor design and has a few flaws.
The design is poor because of the requirement for the routine r1, r2...
It has a flaw, because the windows a closed in reverse order.
By simply extending the original design, the first use of the hotkey is interrupted by the 2nd and latter uses.
so the windows are opened 1,2,3...10 and closed 10,9,8... 1
I may come up with a better version, but not at this moment.
#MaxThreadsPerHotkey 10 if 1 ; screen coordinates coord=screen else coord=relative tooltip, %coord% sleep, 8000 CoordMode, ToolTip, %coord% CoordMode, Pixel, %coord% CoordMode, Mouse, %coord% CoordMode, Caret, %coord% CoordMode, Menu, %coord% tooltip, return f1:: MouseGetPos, X, Y WinMove, % "ahk_pid " P%b_index%, , X, Y return RButton:: b_index++ if b_index >10 b_index=1 MouseGetPos, X, Y Run "irfanview.exe" "cat2.jpg", , , P%b_index% f=r%b_index% if islabel(f) goto %f% ;msgbox oops return r1: winwaitactive, ahk_pid %P1% WinMove, , , X, Y Sleep 8000 WinClose, return r2: winwaitactive, ahk_pid %P2% WinMove, , , X, Y Sleep 8000 WinClose, return r3: winwaitactive, ahk_pid %P3% WinMove, , , X, Y Sleep 8000 WinClose, return r4: winwaitactive, ahk_pid %P4% WinMove, , , X, Y Sleep 8000 WinClose, return r5: winwaitactive, ahk_pid %P5% WinMove, , , X, Y Sleep 8000 WinClose, return r6: winwaitactive, ahk_pid %P6% WinMove, , , X, Y Sleep 8000 WinClose, return r7: winwaitactive, ahk_pid %P7% WinMove, , , X, Y Sleep 8000 WinClose, return r8: winwaitactive, ahk_pid %P8% WinMove, , , X, Y Sleep 8000 WinClose, return r9: winwaitactive, ahk_pid %P9% WinMove, , , X, Y Sleep 8000 WinClose, return r10: winwaitactive, ahk_pid %P10% WinMove, , , X, Y Sleep 8000 WinClose, return +esc::exitapp f11::listvars f12::reload #singleinstance force
BTW, did you know that AHk can display some image formats directly, without the need for irfanview.exe ?
#7
-
Posted 07 January 2012 - 01:18 AM