topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Wednesday December 11, 2024, 6:48 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: autohotkey - reload script on screen number change  (Read 22354 times)

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • View Profile
    • Donate to Member
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 AM by nudone »

cthorpe

  • Discount Coordinator
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 738
  • c++thorpe
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #1 on: July 19, 2010, 09:31 AM »
Looks like this is where one will need to start:

http://www.autohotke.../commands/SysGet.htm

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

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #2 on: July 19, 2010, 10:11 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).

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #3 on: July 19, 2010, 06:19 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

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #4 on: July 19, 2010, 06:51 PM »
i'm using ActualWindowManager http://www.actualtoo...s.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.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #5 on: July 19, 2010, 07:11 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?

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #6 on: July 19, 2010, 07:17 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:




nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #7 on: July 20, 2010, 02:17 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  :)

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.

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #8 on: July 20, 2010, 03:49 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.

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #9 on: July 20, 2010, 05:38 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)

sysget, Count, monitorcount
settimer, Mon_Count,10000

put this bit at the bottom of your script

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

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #10 on: July 21, 2010, 04:18 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.)

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #11 on: July 21, 2010, 06:06 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


MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #12 on: July 21, 2010, 07:26 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



nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #13 on: July 21, 2010, 09:26 PM »
oh, nice tip.

i really wish i could do more with ahk myself.

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #14 on: July 21, 2010, 09:34 PM »
oh, nice tip.

i really wish i could do more with ahk myself.

you are :Thmbsup:

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #15 on: July 22, 2010, 01:38 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.




jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: autohotkey - reload script on screen number change
« Reply #16 on: January 18, 2011, 12:23 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 :( ]