V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
CivAx
V2EX  ›  程序员

应昨天老哥的奇怪要求,用 AHK 琢磨了一个双鼠标切换(伪)

  •  
  •   CivAx · 2019-11-20 12:06:14 +08:00 · 1795 次点击
    这是一个创建于 1611 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://www.v2ex.com/t/621030

    适用于双屏,能模拟实现单鼠标双指针(伪),通过 F10 或者自定义的按键来切换两个指针的位置

    适用于双屏是因为再多的屏就模拟不出来效果了( doge

    少废话,先看东西

    CoordMode, ToolTip, screen
    CoordMode, Mouse, screen
    CoordMode, Pixel, screen
    
    SplashImageGUI(img, X, Y)
    {
     	Gui, CURSOR:Margin , 0, 0 
    	Gui, CURSOR:Add, Picture,, %img%
    	Gui, CURSOR:+LastFound -Caption +AlwaysOnTop +ToolWindow -Border
    	Winset, TransColor, White
    	Gui, CURSOR:Show, xCenter yCenter
    	return
    }
    
    
    ;==============================================================================
    ;  simulated 2nd cursor, press F10 swap the positions of the two cursors
    ;==============================================================================
    
    image = mouse.png
    SplashImageGUI(image, "Center", "Center")
    return
    
    ; in case of emergency, hit escape ;)
    esc::exitapp
    return
    
    
    ;=======================================================
    ; swap the positions of the cursors
    ;=======================================================
    
    f10::
    blockinput, on ; block keyboard & moouse during the swap
    
    MouseGetPos, xpos, ypos
    
    winmove, switchCursor.ahk,, %xpos%, %ypos%
    
    MouseMove, xloc, yloc ,0
    xloc := xpos
    yloc := ypos
    
    blockinput, off
    return
    

    脚本命名请对应 winmove 中的窗口名,如果你把 AHK 封装成了 exe 文件,请注意修改这里

    F10 切换两个指针,ESC 退出。如果你在调试请将 blockinput 设为 off ;如果你不幸地,被 blockinput 后才看到这段话,请 Ctrl+Alt+Del,奇异博士教过我们看书要先看注意事项。

    image 随便找一个鼠标图片,把背景抠成透明,然后用 Windows 的画图 resize 一下大小,再点保存就会变成白底(很重要),再跟脚本丢到同一个目录就行了。因为透明效果靠 Winset, TransColor, White 实现,如果是透明图片,载入时会变成黑底。

    @vtoexshan

    6 条回复    2019-11-21 22:58:46 +08:00
    locoz
        1
    locoz  
       2019-11-20 12:22:13 +08:00 via Android
    你好骚啊
    karnaugh
        2
    karnaugh  
       2019-11-20 12:33:40 +08:00
    奇♂怪♂需♂求
    jin7
        3
    jin7  
       2019-11-20 12:38:01 +08:00
    推荐一个找图工具
    http://ahkcn.net/thread-5029.html
    vtoexshan
        4
    vtoexshan  
       2019-11-20 13:14:21 +08:00
    感谢老哥出手!
    cweijan
        5
    cweijan  
       2019-11-21 21:19:54 +08:00
    不错
    cweijan
        6
    cweijan  
       2019-11-21 22:58:46 +08:00   ❤️ 2
    做了一些改进, 确保能够切换屏幕

    ```
    ; #NoTrayIcon
    #SingleInstance force

    CoordMode, Mouse, screen

    f10::
    SysGet, MonitorCount, MonitorCount
    SysGet, Mon, Monitor, %MonitorCount%
    MouseGetPos, xpos, ypos
    if(xpos>MonLeft){
    ;; in second monitor
    x2 := xpos
    y2 := ypos
    if(x1="" ){
    x1 := MonLeft/2
    y1 := MonBottom/2-100
    }
    MouseMove, x1, y1 ,0
    }else{
    ;; in first monitor
    x1 := xpos
    y1 := ypos
    if(x2=""){
    x2 := MonLeft+((MonRight-MonLeft)/2)
    y2 := MonBottom/2-100
    }
    MouseMove, x2, y2 ,0
    }
    return
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5684 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 02:30 · PVG 10:30 · LAX 19:30 · JFK 22:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.