Sign in to follow this  
Followers 0
sshrum

Script to move active window to other monitors

18 posts in this topic

#1 ·  Posted (edited)

I was reading a post and saw the link to this thread:

http://www.autoitscript.com/forum/index.ph...mp;hl=_splitmon

Then I got the idea (since I run 3 monitors) that it would be a kewl to have something that could run in the background that would capture a hotkey (or keys) and move the active window to the screen of my choosing.

I envision the following:

+ WinKey+left arrow = move active window the the monitor on the left

+ WinKey+up arrow = move active window to the primary monitor

+ WinKey+right arrow = move active window to to monitor on the right

+ WinKey+1 = move active window to monitor 1

+ WinKey+2 = move active window to monitor 2

+ WinKey+n = move active window to monitor n

I'm thinking of other options for things like 'move and maximize', etc.

My question is, how to deal with positioning the active window based on the screen I want it to drop into.

TIA

BTW: is there a way to capture the 'Window' key? You know, the one that pops up your start menu. :whistle:

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites



BTW: is there a way to capture the 'Window' key? You know, the one that pops up your start menu. :whistle:

From Help file _IsPressed

5B Left Windows key

5C Right Windows key


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

sshrum, I just posted over at the splitmon topic, but to capture the windows key you would actually want to do something like:

HotKeySet("#1", "MoveFunction")

The "#" is the windows key. Make the above into a for loop and you've got your nth degree deal. You can see an example of this in my splitmon code too, just search for "Hotkeyset".

Share this post


Link to post
Share on other sites

Huh...

Seems that Vista has the WinKey+Number combos hotkeyed already...

1-0 coorespond to the shortcuts on your quick launch bar. So....

If you have a shortcut to Media Player first on your quick launch bar, WinKey+1 launches it.

Was it like this in XP or is this a new Vista feature???


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites

Huh...

Seems that Vista has the WinKey+Number combos hotkeyed already...

1-0 coorespond to the shortcuts on your quick launch bar. So....

If you have a shortcut to Media Player first on your quick launch bar, WinKey+1 launches it.

Was it like this in XP or is this a new Vista feature???

not in XP... I bet there's a way to disable in vista though. No idea how, but i bet there is :whistle:

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hells yea...I rock! Figured it out.

Here are the dets.

I calculate the positions (left to right) of the monitors based on their X (left) value.

Monitors to the left of the primary moinitor have negative X values; those to the right have positive, while the primary monitor has a 0 value for X.

I used Fisofo's _MonitorInfo() routine from http://www.autoitscript.com/forum/index.ph...mp;hl=_splitmon to collect the multi-monitor data and pulled all the X values into a single-dim array. I then sort the array and come up with a 1-2-3-4 order of monitors from left to right. Based on the active windows X position, I can calculate what monitor (the left window corner) is on (this is gunna need some tweaking).

No docs on the code yet but CTRL+left moves the active window to the next monitor on the left. If the window is on the extreme left monitor, it will roll over to the far right monitor. Same for CTRL+right (just in reverse).

Another option is CTRL+(monitor #). If a window is on monitor 1, you can use CTRL+3 (on a 3 monitor setup) to move the window to monitor 3. Currently, my script supports UP TO NINE MONITORS!

I've added hotkeys of CTRL+UP for maximizing the active window on the screen it's currently on and CTRL+DOWN to take the active window from maximized -> restored -> minimized.

Right now, when a window is moved, it is maximized on the screen it was sent to.

I saw some problems (in Vista since that is what I'm running) when attempting to move a MAXIMIZED window...so the script will RESTORE the window, MOVE it, and then MAXIMIZE it.

Long story short...it works great for me.

I'll post the code and bin later to http://www.shrum.net/code/switchmon

P.S. _MonitorInfo returns info on the monitors based on their Enum'ed order...1 is monitor1, 2 is monitor2, etc. (matches up with the numbers that get displayed when you hit "Identify" in the Display Properties dialog).

Enjoy

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites

Hells yea...I rock! Figured it out.

Here are the dets.

I calculate the positions (left to right) of the monitors based on their X (left) value.

Monitors to the left of the primary moinitor have negative X values; those to the right have positive, while the primary monitor has a 0 value for X.

I used Fisofo's _MonitorInfo() routine from http://www.autoitscript.com/forum/index.ph...mp;hl=_splitmon to collect the multi-monitor data and pulled all the X values into a single-dim array. I then sort the array and come up with a 1-2-3-4 order of monitors from left to right. Based on the active windows X position, I can calculate what monitor (the left window corner) is on (this is gunna need some tweaking).

No docs on the code yet but CTRL+left moves the active window to the next monitor on the left. If the window is on the extreme left monitor, it will roll over to the far right monitor. Same for CTRL+right (just in reverse).

Another option is CTRL+(monitor #). If a window is on monitor 1, you can use CTRL+3 (on a 3 monitor setup) to move the window to monitor 3. Currently, my script supports UP TO NINE MONITORS!

I've added hotkeys of CTRL+UP for maximizing the active window on the screen it's currently on and CTRL+DOWN to take the active window from maximized -> restored -> minimized.

Right now, when a window is moved, it is maximized on the screen it was sent to.

I saw some problems (in Vista since that is what I'm running) when attempting to move a MAXIMIZED window...so the script will RESTORE the window, MOVE it, and then MAXIMIZE it.

Long story short...it works great for me.

I'll post the code and bin later to http://www.shrum.net/code/switchmon

P.S. _MonitorInfo returns info on the monitors based on their Enum'ed order...1 is monitor1, 2 is monitor2, etc. (matches up with the numbers that get displayed when you hit "Identify" in the Display Properties dialog).

Enjoy

Good Job! Would you be interested in incorporating any of this into splitmon? I'm still doing a good deal of development with it... Up to you though. Perhaps some of the hotkeys would be better for the Home/End/Page Up/Page Down, keys, but anyway, we'll see.

For moving a window from monitor to monitor, I'm guessing you had the same problem I did in winxp. Take a look at _NewWinMove() in splitmon; feed it a windows state, and if it is maximized it will move it correctly, I'm not sure what issue you're having, but this may resolve it.

Let me know about the code... I had planned on adding this sort of stuff in at some point anyway, it would sure be easier just to Copy-> Paste :whistle:

Share this post


Link to post
Share on other sites

Would you be interested in incorporating any of this into splitmon?

Absolultely...I kewl with that (After all I'm using your _MonitorInfo() code.) I just need to iron a few things out...seems that when I restore a window on a system running multiple resolutions, if a majority of that window lies on another screen after the move, the maximize goes to the majority screen (which is normal XP/Vista operation). I need to shrink the window size so that he maximize applies to the proper monitor.

P.S.: _SplitMon doesn't like working with system with 3+ monitos (array limits) + in Vista at least, all the resizes smash the windows to the upper left corner with a size like 0,0 :whistle: Works fine in XP...I like the functionality but currently run Vista. If you need a tester and think you got this fixed, let me know.


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites

Absolultely...I kewl with that (After all I'm using your _MonitorInfo() code.) I just need to iron a few things out...seems that when I restore a window on a system running multiple resolutions, if a majority of that window lies on another screen after the move, the maximize goes to the majority screen (which is normal XP/Vista operation). I need to shrink the window size so that he maximize applies to the proper monitor.

P.S.: _SplitMon doesn't like working with system with 3+ monitos (array limits) + in Vista at least, all the resizes smash the windows to the upper left corner with a size like 0,0 :whistle: Works fine in XP...I like the functionality but currently run Vista. If you need a tester and think you got this fixed, let me know.

Cool. Not quite sure what you mean by the maximize issue, but I can wait for the code.

As far as vista goes, I should be up and running on it within the week, so hopefully I can also start doing debugging... but if you have any insight, I'd appreciate it :)

But 3+ monitors is working in XP for you? That's good at least. I wonder if _MonitorInfo() is not detecting stuff properly in Vista? Did you need to modify _MonitorInfo() at all to work in Vista?

Share this post


Link to post
Share on other sites

No..._Spiltmon only works on 2 monites regardless of OS...generates Array subscript errors if more that 3 are found.

As for the _MonitorInfo() code...no mods are needed (I think...it was a long night). I'm using your array results as is and just pulling the [0] (x) values

I'm writing you a self-contained function that you should be able to drop directly into your _splitmon project and call with a hotkey.


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites

No..._Spiltmon only works on 2 monites regardless of OS...generates Array subscript errors if more that 3 are found.

As for the _MonitorInfo() code...no mods are needed (I think...it was a long night). I'm using your array results as is and just pulling the [0] (x) values

I'm writing you a self-contained function that you should be able to drop directly into your _splitmon project and call with a hotkey.

Interesting... I've been waiting to hear if 3 monitors worked or not. I've got a shipment coming in soon for another couple monitors, then I'll be able to test 4! Anyway, that should help get the bugs ironed out.

Thanks for the work on the code... I'm thinking it might actually be cool to use the arrows as you are, and leave the rest of the SplitMon functions to the Numpad. Then again, I aught to make it more easily customizable from the GUI... we'll see. Anyway, look forward to the update.

Share this post


Link to post
Share on other sites

Done....it still needs a a good bit of testing but so far it works great on my system. Homepage and Help links in the SysTray menu will bring up blank pages until I get around to doing them.

HotKey combos are:

...WinKey+Left - moves the active window to the next left screen and maximizes. If on far left screen, wraps to far right screen

...WinKey+Right - moves the active window to the next right screen and maximizes. If on far right screen, wraps to far left screen

...WinKey+Up - maximizes the active window

...WinKey+Down - restores the active window

...WinKey+End - exits app

Code here: http://www.shrum.net/code/relocate/source/v.1

Bin here: http://www.shrum.net/code/relocate/bin

Let me know what you think.

:whistle:


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites

Done....it still needs a a good bit of testing but so far it works great on my system. Homepage and Help links in the SysTray menu will bring up blank pages until I get around to doing them.

HotKey combos are:

...WinKey+Left - moves the active window to the next left screen and maximizes. If on far left screen, wraps to far right screen

...WinKey+Right - moves the active window to the next right screen and maximizes. If on far right screen, wraps to far left screen

...WinKey+Up - maximizes the active window

...WinKey+Down - restores the active window

...WinKey+End - exits app

Code here: http://www.shrum.net/code/relocate/source/v.1

Bin here: http://www.shrum.net/code/relocate/bin

Let me know what you think.

:whistle:

Thank you good sir :) I will take a look at the code tonight and start monkeying with it. You may want to request a mod move this topic to example scripts as it's no longer a question.

Oh, and if you do that, update the first post :

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Not to steal Fisofo's thunder, but I added numpad positioning to my script as well.

Imitation is the sincerest form of flattery :">

FISOFO: Get the latest version of my relocate function...I found a couple of issues in the 1.00 release that I think I have ironed out...may be some more in there but I'll fix them as soon as I hear/find them.

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites

Not to steal Fisofo's thunder, but I added numpad positioning to my script as well.

Imitation is the sincerest form of flattery :

FISOFO: Get the latest version of my relocate function...I found a couple of issues in the 1.00 release that I think I have ironed out...may be some more in there but I'll fix them as soon as I hear/find them.

FINE, be that way!! Just kidding! :):whistle:

I really don't mind, I'm going to be using your functions in mine, so no big deal, right? Thanks for giving credit though!

Share this post


Link to post
Share on other sites

Your Code really looks like what I'm looking for.

But I wanne change the hotkeys because Winkey is used by another application. I would prefer ALT+CTRL+LEFT but I was not able to realize that. ALT+CTRL+"l" works great "^!l" but I don't know how to ALT+CTRL and arrow keys.

My second problem is that I just want to move a fullscreen or normal size window to the second or first screen without split windows.

Maybe you or anybody else has an idea.

Share this post


Link to post
Share on other sites

Hi,

I think Splitmon is really cool. I just miss two functions. It would be cool if the user were able to move the mouse with the window with a serperate modifier key. Maybe something like that. WIN+Arrow --> move window, Win+Arrow+Shift --> move window with mouse. And my second wish is to span a single windows over all displays, with a keyboard shortcut of course.

Finally i recognized that spiltmon will crash if i connect to a dual display machine with rdp (remote desktop). If there will be a fix splitmon would be perfect.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0