Welcome Guest.   Make a donation to an author on the site October 31, 2014, 05:13:11 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2012! Download dozens of custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: DONE: autohotkey - reload script on screen number change  (Read 8908 times)
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« on: July 19, 2010, 09:20:02 AM »

a few credits are awaiting if you can just write a bit of a script that does the following, please...

1. monitor number of screens (physical LCD monitors) currently enabled.

2. when number of screens changes - RELOAD a specific ahk script - or, list of scripts.

3. keep monitoring number of screens ready for next reload of script(s).


the problem is that i swap between single screen enabled and multi-screen enabled quite often and i forget to reload my autohotkeyscripts. this means that one of the scripts, DialogMove, isn't aware that the screen number has changed and so doesn't work correctly (until i reload it).

i'd ask Jgpaiva if he'd modify the DialogMove script but:

a: i think he's far to busy.
b: i think that the script i'm requesting might be useful with other scripts that need reloading (or programs that need reloading that i don't know of right now). so, just asking for DialogMove to be modified wouldn't help with other, potential, script problems.

thanks.

edit:
i've just realised i've another program running that doesn't appreciate when enabled screens has changed. it's a small util called "Y'z Shadow".

so, it would be very helpful if the script i've requested above does also have the ability to load in exe files and not just scripts.

thanks again.
« Last Edit: July 19, 2010, 09:25:36 AM by nudone » Logged
cthorpe
Discount Coordinator
Supporting Member
**
Posts: 719


c++thorpe

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #1 on: July 19, 2010, 09:31:12 AM »

Looks like this is where one will need to start:

http://www.autohotkey.com/docs/commands/SysGet.htm

Quote
Parameters
OutputVar    The name of the variable in which to store the result.
Sub-command    See list below.
Param3    This parameter is omitted except where noted below.
Sub-commands

MonitorCount: Retrieves the total number of monitors. Unlike SM_CMONITORS mentioned in the table below, MonitorCount includes all monitors, even those not being used as part of the desktop. On Windows 95/NT the count is always 1.

MonitorPrimary: Retrieves the number of the primary monitor, which will be 1 in a single-monitor system. On Windows 95/NT the primary monitor is always 1.

Monitor [, N] : Retrieves the bounding coordinates of monitor number N (if N is omitted, the primary monitor is used). The information is stored in four variables whose names all start with OutputVar. If N is too high or there is a problem retrieving the info, the variables are all made blank. For example:
SysGet, Mon2, Monitor, 2
MsgBox, Left: %Mon2Left% -- Top: %Mon2Top% -- Right: %Mon2Right% -- Bottom %Mon2Bottom%.

Within a function, to create a set of variables that is global instead of local, declare Mon2 as a global variable prior to using this command (the converse is true for assume-global functions).

MonitorWorkArea [, N]: Same as the above except the area is reduced to exclude the area occupied by the taskbar and other registered desktop toolbars.

MonitorName [, N]: The operating system's name for monitor number N (if N is omitted, the primary monitor is used).

(Numeric): Specify for Sub-command one of the numbers from the table below to retrieve the corresponding value. The following example would store the number of mouse buttons in a variable named "MouseButtonCount":
SysGet, MouseButtonCount, 43
Logged
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #2 on: July 19, 2010, 10:11:22 AM »

okay, thanks, cthorpe.

there is an example at the bottom of that page that seems straightforward. i'll try to work something out, later in the week, if no one else jumps in with a quick solution (it will take me all day trying to get the if statements set up i'm sure).
Logged
Target
Honorary Member
**
Posts: 1,410



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #3 on: July 19, 2010, 06:19:51 PM »

how do you intiate the switch between the...errr....2?

I'm thinking this is the point you'd probably want to look at
Logged

"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #4 on: July 19, 2010, 06:51:53 PM »

i'm using ActualWindowManager http://www.actualtools.com/windowmanager/ to control the number of monitors/screens enabled at any one time.

this is done through a tray icon's context menu - which provides the options of enabling or disabling any 1 of the four monitors plugged in.

if i could remember, i'd simply manually reload Dialogmove (etc.) when i change the number of monitors that are enabled. i just don't make the change often enough to remember - not until i expect Dialogmove to do its magic and i realise it hasn't because of the screen change.

i suppose, Dialogmove could be modified to work in the "all screens enabled" mode at all times. well, maybe, as i really don't know if that's remotely possible.




i think all the new script needs to do is constantly monitor the "desktop" size using the SysGet properties. when it detects a change in the previously stored "desktop" size the script reloads whatever programs and scripts are in the preset list. i'm assuming that it is a simple matter for one script to reload another script that is already running - or kill a program running in the tray and restart it.

or, it could monitor the number of screens active instead of desktop size. not sure which is more likely to work or run into trouble.
Logged
skwire
Global Moderator
*****
Posts: 4,119



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #5 on: July 19, 2010, 07:11:37 PM »

How elegant do you want this?  I mean, what you want to do is a piece of cake in the scripting sense but did you want a nice GUI and such to go along with it?
Logged

Target
Honorary Member
**
Posts: 1,410



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #6 on: July 19, 2010, 07:17:44 PM »

I've just had a quick look at the doc's and it appears that the switching is done via hotkey (I'm also assuming that what you're doing is disabling/enabling your 'secondary'monitors)

this being the case you can simply add the same hotkey to your AHK script (DialogMove?) that sends the hotkey AND reloads the script, eg

    ^!F12::
    send ^!F12
    reload
    return

    +^!F12::
    send +^!F12
    reload
    return

you'll need ot check the syntax of the send command (I rarely use it so I always need to work it out each time...)

the returns are redundant in this case but it looks wrong to leave them out huh



Logged

"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #7 on: July 20, 2010, 02:17:36 AM »

ooh, i like that, Target. i wasn't using the hotkeys (without a good reason; just lazy) so i'll check that ActualWindowManager works correctly that way. that would be enough to keep me happy for a while  smiley

but, skwire, as for looking pretty, that wasn't important really. i was first just hoping for a few lines of script that i could edit maybe. the real problem is that it could be a very simple bit of code - but it would probably take me a couple of days (or more) to figure out myself. unless i hit lucky.

so, Targets idea will work quite well, i think, just for reloading Dialogmove. but it would be nice if i had a little script i could add to and reload/restart other scripts and exe files. i assume i can just add the same Target hotkey method to all the scripts i want to reload - maybe i just need a script that uses the very same hotkey to kill and restart a list of apps running in the tray...

...this is assuming that ActualWindowManager will behave as expected using the hotkeys.

i'll report back when i've got to my main pc and tried it.

p.s.
it would still be nice to have a script that automatically reloads stuff when detecting the number of screens enabled changes.
Logged
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #8 on: July 20, 2010, 03:49:18 AM »

Target's method of adding the hotkeys to DialogMove works. i'm not entirely sure if it works perfectly as there seems to be a problem "making things happen". that might just be the keyboard itself, seems i have to hold the keys down longer than expected before the system recognises what i'm doing.

i'll keep testing it out and report back.
Logged
Target
Honorary Member
**
Posts: 1,410



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #9 on: July 20, 2010, 05:38:09 PM »

ok, here's an automagic method - use a timer to fire a routine that counts the number of monitors and if the numbers don't match, reload

put this bit at the top of your script (DialogMove)

[copy or print]
sysget, Count, monitorcount
settimer, Mon_Count,10000

put this bit at the bottom of your script

[copy or print]
Mon_Count:
sysget, tmp_, monitorcount

if tmp_ = %count%
    return

reload
return
 

you could reload any number of scripts/apps using run commands, or you could do this from a list (ini), but you need to make sure to add the run commands before the reload command, and any other AHK scripts will need to use #singleinstance, force

NOTE - I don't have multiple monitors so this is untested, but it should work
Logged

"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #10 on: July 21, 2010, 04:18:33 AM »

thanks, Target.

that auto reload appears to be working well. and helps me more than using a hotkey combination - as i will forget what that is. so, now, i can just use the ActualWindowManger tray menu to enable/disable the active screens - and the auto reload script does everything else.

(a few credits sent - hope that is, okay.)
Logged
Target
Honorary Member
**
Posts: 1,410



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #11 on: July 21, 2010, 06:06:10 PM »

that auto reload appears to be working well. and helps me more than using a hotkey combination - as i will forget what that is. so, now, i can just use the ActualWindowManger tray menu to enable/disable the active screens - and the auto reload script does everything else.

(a few credits sent - hope that is, okay.)

glad to be able to help

not being able to test it I wasn't altogether sure whether or not it would work, so that's good news

FYI you can use both so you have the hotkey option as well if you want/need it

Logged

"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
MilesAhead
Member
**
Posts: 4,970



View Profile WWW Give some DonationCredits to this forum member
« Reply #12 on: July 21, 2010, 07:26:24 PM »

I've just had a quick look at the doc's and it appears that the switching is done via hotkey (I'm also assuming that what you're doing is disabling/enabling your 'secondary'monitors)

this being the case you can simply add the same hotkey to your AHK script (DialogMove?) that sends the hotkey AND reloads the script, eg

    ^!F12::
    send ^!F12
    reload
    return

    +^!F12::
    send +^!F12
    reload
    return

you'll need ot check the syntax of the send command (I rarely use it so I always need to work it out each time...)

the returns are redundant in this case but it looks wrong to leave them out huh





Instead of catching a hotkey, then resending, try prefixing the hotkey with '~'
It won't "eat" the hotkey in that case. Should look like:

~+^!F12::
yadda yadda
Return


Logged

"Genius is not knowing you can't do it that way."
- MilesAhead
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #13 on: July 21, 2010, 09:26:22 PM »

oh, nice tip.

i really wish i could do more with ahk myself.
Logged
Target
Honorary Member
**
Posts: 1,410



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #14 on: July 21, 2010, 09:34:12 PM »

oh, nice tip.

i really wish i could do more with ahk myself.

you are Thmbsup
Logged

"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
MilesAhead
Member
**
Posts: 4,970



View Profile WWW Give some DonationCredits to this forum member
« Reply #15 on: July 22, 2010, 01:38:39 PM »

oh, nice tip.

i really wish i could do more with ahk myself.

It can be frustrating sometimes with the different languages. ahk is great for mouse hotkey especially.  I've just started playing around with FreeBASIC. It produces tiny stand-alone exes since I guess it gets translated into assembly code and assembled.  Stuff is there for a lot of Windows API calls like ShellExecute and that type of thing, but using an ActiveX the only way is a 3rd party user library. It's not as smooth as AutoIt3 or Python for creating an ax object.  But for quickie command line stuff it's cool. It's freaky to compile a program and see the exe < 10 KB. It's been ages since I did anything with Basic.



Logged

"Genius is not knowing you can't do it that way."
- MilesAhead
jgpaiva
Global Moderator
*****
Posts: 4,711



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #16 on: January 18, 2011, 12:23:59 PM »

Actually I had this code already implemented for GridMove but ended up disabling it due to some people having trouble.
The script I've attached to this post should work. Just pass it the executables you want it to run when it detects a monitor change.
[warning: it's untested, as I don't have a Windows machine now Sad ]

* ReloadOnResolutionChange.ahk (2.39 KB - downloaded 101 times.)
Logged

Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.042s | Server load: 0.16 ]