AutoHotkey script for quick resizing and repositioning

Post Reply
User avatar
triple_lei
Posts: 178
Joined: Fri Oct 12, 2012 3:42 am
Location: Los Angeles, California
Contact:

AutoHotkey script for quick resizing and repositioning

Post by triple_lei » Wed Feb 08, 2023 5:31 am

*Now working with 3ds_capture.5.2

Quick demo: https://youtu.be/3t6zEnJP7Xo

Inspired by gamerguy80's setup and not-unreasonable complaint of not enough presets, I've been working on an AutoHotkey script to quickly resize and reposition the capture window displays with a single key press. You just need to install AutoHotkey, copy this code here into a .txt file called "New 3DS XL Capture Resizing" (or anything else, but ideally that) and then rename the extension from .txt to .ahk:

Code: Select all

SetTitleMatchMode, 2
+PrintScreen::Suspend	; Shift & PrintScreen to toggle suspend
#PrintScreen::Edit	; Windows Key & PrintScreen to edit
#IfWinActive, New 3DS XL Capture Resizing.ahk - Notepad
~^s::
reload
return
#IfWinActive
; automatic reloading



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
  _    _                 _______ _     _      __          __        _        
 | |  | |               |__   __| |   (_)     \ \        / /       | |       
 | |__| | _____      __    | |  | |__  _ ___   \ \  /\  / /__  _ __| | _____ 
 |  __  |/ _ \ \ /\ / /    | |  | '_ \| / __|   \ \/  \/ / _ \| '__| |/ / __|
 | |  | | (_) \ V  V /     | |  | | | | \__ \    \  /\  / (_) | |  |   <\__ \
 |_|  |_|\___/ \_/\_/      |_|  |_| |_|_|___/     \/  \/ \___/|_|  |_|\_\___/
*/

/*

This script uses the number pad (and ONLY the number pad!) to quickly resize
and reposition the capture windows. 

It also takes full advantage of the newest experimental build of the capture
software (currently 3ds_capture_20230214.exe) which adds the following: 

- (20230214) Will notice external repositioning.
- (20230210) Rounded corners are gone.
- (20230210) "Hide border" setting was added.
- (20230210) Push Ctrl-0..9 to store a preset, and 0..9 to load it.

As long as you use the QWERTY row of numbers for saving and loading, you
shouldn't have any problems saving/loading presets and running this script
at the same time.



Your number pad and this script's functions at a glance:
.---------------------------------------------------------------------------.
|           7             |           8            |            9           |
|                         |                        |                        |
|       reposition        |     toggle borders     |       reposition       |
|       top screen        |        on / off        |     bottom screen      |
|  (use w/ borders off)   |      (same as F5)      |  (use w/ borders off)  |
|-------------------------+------------------------+------------------------|
|           4             |           5            |            6           |
|                         |                        |                        |
|  resize top or bottom   |  move any 3DS capture  |  toggle split window   |
|  screen (borders off)   |    window to center    |        on / off        |
|    to native res x4     |                        |      (same as F2)      |
|-------------------------+------------------------+-----------------------=|
|           1             |           2            |            3           |
|                         |                        |                        |
|  resize top or bottom   |  resize top or bottom  |  resize top or bottom  |
|  screen (borders off)   |  screen (borders off)  |  screen (borders off)  |
|  to native resolution   |    to native res x2    |    to native res x3    |
 `--------------------------------------------------------------------------'

There's no real reason to have borders on at all anymore. The hotkeys for
repositioning  (7 and 9) were made assuming borders off, and results will
look wrong with borders on.

When resizing a window with borders on, hold Left Alt before pressing 1-4.
This was made intentionally less convenient to hit because, again, there's
no real reason to have borders on at all.



Table of resolutions for reference:
.---------------------------------------------------------------------------.
|               |  resolution  |  resolution  |  resolution  |  resolution  |
|               |      x1      |      x2      |      x3      |      x4      |
|---------------+--------------+--------------+--------------+--------------|
| Single screen |    400,480   |    800,960   |  1200,1440   |  1600,1920   |
|---------------+--------------+--------------+--------------+--------------|
| Split, top    |    400,240   |    800,480   |   1200,720   |   1600,960   |
|---------------+--------------+--------------+--------------+--------------|
| Split, buttom |    320,240   |    640,480   |    960,720   |   1280,960   |
 `--------------------------------------------------------------------------'



For best results, right click on a screen and choose:

Scaling > Point
Hide Border CHECKED

When playing older games on the 3DS (such as NDS games, and some Virtual 
Console games), hold Start before starting the game to run in native 
resolution, which will give you a smaller but sharper image.
*/



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
  _____                                  _             
 |  __ \                                (_)            
 | |__) |___ _ __ ___   __ _ _ __  _ __  _ _ __   __ _ 
 |  _  // _ \ '_ ` _ \ / _` | '_ \| '_ \| | '_ \ / _` |
 | | \ \  __/ | | | | | (_| | |_) | |_) | | | | | (_| |
 |_|  \_\___|_| |_| |_|\__,_| .__/| .__/|_|_| |_|\__, |
                            | |   | |             __/ |
                            |_|   |_|            |___/ 
*/

; Hit 6 on the number pad acts like F2 (toggles split window view)
#IfWinActive - ahk_exe 3ds_capture.exe
Numpad6::
send {F2}
return
#IfWinActive


; Hit 8 on the number pad acts like F5 (toggles Hide border)
#IfWinActive - ahk_exe 3ds_capture.exe
Numpad8::
send {F5}
return
#IfWinActive




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
  _____           _     _             
 |  __ \         (_)   (_)            
 | |__) |___  ___ _ _____ _ __   __ _ 
 |  _  // _ \/ __| |_  / | '_ \ / _` |
 | | \ \  __/\__ \ |/ /| | | | | (_| |
 |_|  \_\___||___/_/___|_|_| |_|\__, |
                                 __/ |
                                |___/ 
*/



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SINGLE WINDOW BOTH SCREENS                                               :;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Hit 1, 2, 3, or 4 on the number pad to resize to that multiple 
#IfWinActive - ahk_class 3DS Capture - Single
{
  WinGetPos,X,Y,W,H,A88888888
  If %Width% = 0
    Width := W

  If %Height% = 0
    Height := H

  WinMove,A,,%X%,%Y%,%Width%,%Height%
}

; With borders
~LAlt & Numpad1::ResizeWin(416,519)		; x1
~LAlt & Numpad2::ResizeWin(816,999)		; x2

; Without borders
Numpad1::ResizeWin(400,480)		; x1
Numpad2::ResizeWin(800,960)		; x2
return
#IfWinActive



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TOP SCREEN                                                               ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Hit 1, 2, 3, or 4 on the number pad to resize to that multiple
#IfWinActive - ahk_class 3DS Capture - Top
ResizeWin(Width = 0,Height = 0)
{
  WinGetPos,X,Y,W,H,A
  If %Width% = 0
    Width := W

  If %Height% = 0
    Height := H

  WinMove,A,,%X%,%Y%,%Width%,%Height%
}

; With borders
~LAlt & Numpad1::ResizeWin(416,279)		; x1
~LAlt & Numpad2::ResizeWin(816,519)		; x2
~LAlt & Numpad3::ResizeWin(1216,759)	; x3
~LAlt & Numpad4::ResizeWin(1616,999)	; x4

; Without borders
Numpad1::ResizeWin(400,240)		; x1
Numpad2::ResizeWin(800,480)		; x2
Numpad3::ResizeWin(1200,720)		; x3
Numpad4::ResizeWin(1600,960)		; x4
return
#IfWinActive



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; BOTTOM SCREEN                                                            ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Hit 1, 2, 3, or 4 on the number pad to resize to that multiple
#IfWinActive - ahk_class 3DS Capture - Bottom
{
  WinGetPos,X,Y,W,H,A
  If %Width% = 0
    Width := W

  If %Height% = 0
    Height := H

  WinMove,A,,%X%,%Y%,%Width%,%Height%
}

; With borders
~LAlt & Numpad1::ResizeWin(336,279)		; x1
~LAlt & Numpad2::ResizeWin(656,519)		; x2
~LAlt & Numpad3::ResizeWin(976,759)		; x3
~LAlt & Numpad4::ResizeWin(1296,999)	; x4

; Without borders
Numpad1::ResizeWin(320,240)		; x1
Numpad2::ResizeWin(640,480)		; x2
Numpad3::ResizeWin(960,720)		; x3
Numpad4::ResizeWin(1280,960)		; x4
return
#IfWinActive



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
  _____                      _ _   _             _             
 |  __ \                    (_) | (_)           (_)            
 | |__) |___ _ __   ___  ___ _| |_ _  ___  _ __  _ _ __   __ _ 
 |  _  // _ \ '_ \ / _ \/ __| | __| |/ _ \| '_ \| | '_ \ / _` |
 | | \ \  __/ |_) | (_) \__ \ | |_| | (_) | | | | | | | | (_| |
 |_|  \_\___| .__/ \___/|___/_|\__|_|\___/|_| |_|_|_| |_|\__, |
            | |                                           __/ |
            |_|                                          |___/ 
*/

; CENTERING
; Hit 5 on the number pad to move any window to center
#IfWinActive - ahk_exe 3ds_capture.exe		
Numpad5::
WinExist("A")
WinGetPos,,, sizeX, sizeY
WinMove, (A_ScreenWidth/2)-(sizeX/2), (A_ScreenHeight/2)-(sizeY/2)
return
#IfWinActive



; BELOW: 7 moves the top screen and 9 moves the bottom
; The "a" and "b" refer to variations for monitors are 2560x1080 (a) and 1920x1080 (b)



; Hit 7 on the number pad to move top screen
#IfWinActive - ahk_exe 3ds_capture.exe		
Numpad7::
WinExist("A")
WinGetPos,,, sizeX, sizeY
WinMove, 0,0			; Config 1a (1920x1080)	- use at 4x
	; WinMove, 320,40			; Config 2a (2560x1080)
return
#IfWinActive



; Hit 9 on the number pad to move bottom screen
#IfWinActive - ahk_exe 3ds_capture.exe		
Numpad9::
WinExist("A")
WinGetPos,,, sizeX, sizeY
WinMove, 1600,0			; Config 1a (2560x1080)	- use at 3x
	; WinMove, 1920,760		; Config 2b (2560x1080)
return
#IfWinActive



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
  _______          _       
 |__   __|        | |      
    | | ___     __| | ___  
    | |/ _ \   / _` |/ _ \ 
    | | (_) | | (_| | (_) |
    |_|\___/   \__,_|\___/ 
*/

/*
- More templates, along with their 1080p counterparts!
- Maybe touch on why integer scaling is important 
  - https://youtu.be/TI60A3DpI6w?t=275
- Wacky fun with OnTopReplica 
  - https://github.com/LorenzCK/OnTopReplica
- Get back to making AviSynth templates, with the goal of doing this:
  - https://youtu.be/a_4lnZn7ZMI
*/
Double click to run the script (you should see the green AutoHotkey in your tray icons). While the script is running, hit the keys on the number pad to resize or move the capture windows (but hide borders first!):

1 = native resolution
2 = native resolution x2
3 = native resolution x3

4 = native resolution x4
5 = center the window on your main monitor
6 = same as F2 (toggle split window / single window)

7 = move top screen (currently set at 0,0 which is the upper-left of your monitor - ideally, set to x4 on an ultrawide monitor)
8 = same as F5 (toggle hide borders)
9 = move bottom screen (currently set to fill the rest of the horizontal space at x3 on an ultrawide monitor)

There are still plenty of presets to dial in but I've already got my ideal (x4 top screen on the left and x3 bottom screen on the right), and that's what this script is currently set up for, so any further presets will be a long time coming. Or, you know, just get the dang numbers yourself. Consider it an exercise!



Old rant on resizing windows with borders (no longer relevant because we can hide them and resizing and repositioning is even easier):
Spoiler
You will notice that the values for the multiples aren't exactly x2, x3, or x4. That's because in addition to the raw pixels being multiplied, I'm also accounting for the borders, title bar, and... something else. While the numbers for resizing & repositioning look to be correct, that was only after more trial and error and measuring pixels again in GIMP. I did grab what I thought were the correct values, but when I tried out my resizings for myself, they were all smaller than I thought. I ended up having to add 16 to all my widths and 39 to all my heights. My repositioning values also all had to be shifted -8 horizontally. This has all been documented and I'm glad I'm not crazy. The short answer is, there's an invisible border we also have to account for. Fun, right? Just got to find the time to read and digest it all!

For reference:

Single screen in x1, x2, x3, x4
400,480 / 800,960 / 1200,1440 / 1600,1920

Top screen in x1, x2, x3, x4
400,240 / 800,480 / 1200,720 / 1600,960

Bottom screen in x1, x2, x3, x4
320,240 / 640,480 / 960,720 / 1280,960


(My old requests arein this spoiler tag, and were implemented very quickly (Thanks, loopy!). Be sure to check loopy's latest posts in this thread for the latest experimental builds of the software!
Spoiler
So, request time:

Windows 11 forces rounded corners for everything that isn't in full screen, which probably isn't ideal for split screen setups. There's something on github to disable exactly this, but it seems stupidly risky (i.e. bricking your system!). Maybe add a "compact mode" like in Media Player Classic that removes all window borders and prevents rounded corners?

"Borderless" view is especially important because I happily found that a 1080p monitor will fit exactly the top screen resized to x4 (1600x960) and the bottom screen in its original 320x240 resolution (1600+320=1920). Ultrawide monitor owners have it even better; the top screen in x4 (1600x960) and the bottom screen at x3 (960x720) also fill the width nicely (1600+960=2560). With the 1-pixel wide borders and those rounded corners, we're losing... well, still not a lot, but it's just enough to make me feel icky.

Oh, and restore focus to the screens when toggling with F2. Should make any future fancy AutoHotkey scripts easier (for me, anyway).
Last edited by triple_lei on Fri Jun 16, 2023 3:37 pm, edited 3 times in total.

User avatar
loopy
Site Admin
Posts: 2314
Joined: Wed Sep 19, 2012 7:44 pm
Contact:

Re: AutoHotkey script for quick resizing and repositioning

Post by loopy » Sat Feb 11, 2023 4:21 am

triple_lei wrote:
Wed Feb 08, 2023 5:31 am
Windows 11 forces rounded corners for everything that isn't in full screen, which probably isn't ideal for split screen setups.
Well, that's annoying. Try this out.
http://3dscapture.com/tmp/3ds_capture_20230210.zip

Rounded corners are gone.
"Hide border" setting was added.
Push Ctrl-0..9 to store a preset, and 0..9 to load it.

User avatar
triple_lei
Posts: 178
Joined: Fri Oct 12, 2012 3:42 am
Location: Los Angeles, California
Contact:

Re: AutoHotkey script for quick resizing and repositioning

Post by triple_lei » Sun Feb 12, 2023 10:51 pm

This new build is great! With the "Hide border" setting, the resizing and repositioning is so much easier when I'm just dealing with the actual pixels, and the windows are now being resized and repositioned exactly how I expect them to be; no funny business with invisible borders messing up the coordinates.

Toggling "Hide border" works, mostly. With the border on, you can drag the window to whatever size you want, then hit F5 to toggle to borderless, and the window will keep the size and lose the border, as expected. It doesn't work the other way, though; starting with a window at native resolution and border off, I can still use my script to force a resize to 1600x960, but hitting F5 at this point shrinks the screen back to native resolution along with readding borders. Probably a weird side-effect of borderless mode also preventing any resizing since there's no border to drag. For now I'll just redo my script to have two sets of resizing hotkeys: Number Pad and Shift + Number Pad for resizing with and without borders.

On the plus side, the position of the actual 3DS portion of the window doesn't change when toggling borders. For instance, if I use my script to move the top screen to the upper-left corner (0,0), the window with the border will leave a gap on the left side (which explains why I had to use -8 instead of 0), but the borderless window will properly move to the corner with no gap. So if I toggle to borderless, move to the corner, and reenable borders, there will be no gap and the window title bar will be off-screen.

The new window size & position presets work as expected besides not saving the AHK-forced resizings of borderless windows, but that's only a problem for people who care to use the script in the first place... and only a temporary one at that. I'll just silently edit my opening post sometime to include the revised script. It's cool that the preset saves your border settings too, so if you had borders off when you saved the preset, you will have borders off when you load, making for one less thing to have to toggle. And it's also nice that this new build plays nice with my script because the stuff in that script is set to work only with the number pad, while the qwerty row of numbers can work for saving and loading presets.

TLDR:
  • Everything works.
  • Anything I could possibly complain about can be fixed or worked around on my end.
  • There's no reason this couldn't be the newest official build.
  • We just need some way to keep track of what our profiles are. :mrgreen:
---

EDIT: Huh, seems when toggling the border, it only preserves the resizing if I resize it by hand and not instantly with the script. I'll just have to live with resizing the borderless windows manually then.

User avatar
loopy
Site Admin
Posts: 2314
Joined: Wed Sep 19, 2012 7:44 pm
Contact:

Re: AutoHotkey script for quick resizing and repositioning

Post by loopy » Wed Feb 15, 2023 5:20 am

http://3dscapture.com/tmp/3ds_capture_20230214.zip

This one is more AutoHotkey friendly, it will notice external repositioning.
Also, (** drum roll **) I've finally merged it with the DS software, it works with all devices now.

Post Reply