[dual monitor] move mouse cursor to the center of active window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Henrryparth
Posts: 1
Joined: 29 Dec 2018, 04:54

[dual monitor] move mouse cursor to the center of active window

29 Dec 2018, 05:04

hi, i am using a dual monitor setup,
just wondering is it possible to make a script movies download movies at forum that i click a hot key, for example "ctrl+shift+alt+m", then the mouse cursor will move to the center position of active window in the second monitor that i use and vice versa
Last edited by Henrryparth on 30 Dec 2018, 00:28, edited 1 time in total.
M_L
Posts: 13
Joined: 21 Mar 2016, 06:54

Re: [dual monitor] move mouse cursor to the center of active window

09 Jan 2019, 08:20

Here you go @Henrryparth

Code: Select all

CenterMouseOnActiveWindow:
    Sleep 50
    CoordMode,Mouse,Screen
    WinGetPos, winTopL_x, winTopL_y, width, height, A
    winCenter_x := winTopL_x + width/2
    winCenter_y := winTopL_y + height/2
    ;MouseMove, X, Y, 0 ; does not work with multi-monitor
    DllCall("SetCursorPos", int, winCenter_x, int, winCenter_y)
    ;Tooltip winTopL_x:%winTopL_x% winTopL_y:%winTopL_y% winCenter_x:%winCenter_x% winCenter_y:%winCenter_y%
return
Net_Wars
Posts: 51
Joined: 10 Oct 2018, 11:11

Re: [dual monitor] move mouse cursor to the center of active window

09 Jan 2019, 10:56

@M_L
MouseMove is working with second monitor. Big disadvantage of this is that You must have second monitor always in the same place.
@Henrryparth
This code should work

Code: Select all

 CoordMode,Mouse,Screen
^+!m::
screenposH:=1 ;put 1 for 2nd screen above 1st, and -1 for 2nd screen below 1st or if verticaly set to 0
screenposV:=0 ;put 1 for 2nd screen on the left, and -1 for 2nd screen on the right or if horizontaly set to 0
;put here your second screen resolution
screenresX:=0 ;if screens set horizontally set to 0 ScreenResX
screenresY:=1080 ;if screens stacked verticaly set to 0 ScreenResY
MouseMove, (A_screenwidth/2)-(screenresX*screenposV), (A_screenheight/2)-(screenresY*screenposH)
return
Edit: This code is almost working :headwall:
If there is somebody who can check what is wrong with my code I will very appreciate :thumbup:
Hi,
I was trying make this on my own but I'm good only in basics not good even in basics. :facepalm:

Sorry for my bad English. If something is unclear I will try better next time. :headwall:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jeves, mikeyww and 289 guests