Skip to content
The Chat Archive
gpt-4o-2024-08-06· OpenAI WildChat-4.8M (AI2)

Make a autohotkey script that will move my mouse from main monitor 2 to monitor 1 when i…

  1. User

    Make a autohotkey script that will move my mouse from main monitor 2 to monitor 1 when i click F8

  2. Assistant

    Certainly! To achieve the behavior you describe, you can use AutoHotkey, a scripting language for Windows that allows you to automate repetitive tasks. In this script, I am assuming that monitor 1 is positioned to the left of monitor 2. If your setup is different, you may need to adjust the coordinates accordingly.

    Here's a simple script that will move your mouse cursor from monitor 2 to monitor 1 when you press F8:

    ; Script to move mouse cursor from monitor 2 to monitor 1 when F8 is pressed
    
    F8::
    {
        ; Get the primary monitor's width and height
        SysGet, MonitorCount, MonitorCount
    
        if (MonitorCount < 2)
        {
            MsgBox, There are less than two monitors detected.
            return
        }
    
        SysGet, Monitor1, Monitor, 1
        SysGet, Monitor2, Monitor, 2
    
        ; Calculate center coordinates of monitor 1 based on its resolution
        ; Assuming Monitor 1 is on the left of Monitor 2
        CenterX1 := Monitor1Left + (Monitor1Right - Monitor1Left) / 2
        CenterY1 := Monitor1Top + (Monitor1Bottom - Monitor1Top) / 2
    
        ; Move the mouse cursor to the center of monitor 1
        MouseMove, CenterX1, CenterY1
    }
    return
    

    Instructions:

    1. Install AutoHotkey: If you haven't already, download and install AutoHotkey from the official website.

    2. Create a New Script:

      • Right-click on your desktop or in a folder.
      • Select "New" -> "AutoHotkey Script".
      • Name it something like MoveMouse.ahk.
    3. Edit the Script:

      • Right-click the newly created .ahk file and choose "Edit Script".
      • Copy and paste the script provided above into this file.
      • Save the file and close the editor.
    4. Run the Script:

      • Double-click the .ahk file to run the script.
      • You should now be able to press F8 and have your mouse move to monitor 1.

    Customization:

    • If your second monitor is positioned differently relative to your main monitor, you might have to adjust the CenterX1 and CenterY1 calculations to fit your setup's geometry.

    This script will check for the number of monitors and use SysGet to identify the screen layout, placing the mouse in the center of monitor 1. Make sure your system’s monitor settings match this arrangement for the script to work perfectly.