[AHK] | 您所在的位置:网站首页 › 电脑显示器怎么切换信号源快捷键 › [AHK] |
显示器输入源快速切换
前言DDC/CI 协议简介Auto Hot Key简介显示器输入源快捷键切换ahk脚本代码获取你的显示器的输入源id编译成.exe可执行文件
前言
当你有多台设备需要共用一台显示器,这个时候通过显示器物理按键频繁切换显示器输入源就会比较麻烦。如果我们可以通过快捷键的方式切换的话,将会方便不少。 本文将介绍如何在windows环境下使用ahk脚本实现显示器输入源快捷键切换。 参考资料:https://www.chiphell.com/thread-2248082-1-1.html DDC/CI 协议简介DDC/CI协议是Display Data Channel Command Interface的简称。基于DDC/CI协议,用户可以通过鼠标和人性化的软件界面来完成显示器的各项设置和色彩调节,而不必使用传统的OSD菜单。 以上简介来自百度百科,其实DDC/CI协议说白了就是可以让我们连接显示器的设备与显示器之间进行通信,方便我们调节显示器的设置。 本文所介绍的显示器输入源快速切换的方法需要你的显示器支持DDC/CI协议,请确保你的显示器支持该协议并打开该设置。 Auto Hot Key简介Auto Hot Key是一款免费的、Windows下开源的热键脚本语言。也可以通过命令调用系统接口及程序,并创建基于简单语言的图形化界面的执行程序。 官网地址:Auto Hot Key 如果你的电脑没有安装Auto Hot Key,你可以访问以上官网进行下载安装。 显示器输入源快捷键切换ahk脚本代码首先新建一个.ahk文件。 然后在该文件中写入以下代码: (其中切换各个输入源的id需要你根据你自己的显示器去更改,以下是适用于aoc u2790pqu显示器的ahk脚本,我还测试了benq ew2770qz显示器,也可以使用) ; 函数getMonitorHandle()和destroyMonitorHandle(handle)涉及到windows编程,本人水平有限,没弄懂如何编写,只会使用,感兴趣的可以自己看看英文原注释 ; Finds monitor handle based on MousePosition getMonitorHandle() { ; Initialize Monitor handle hMon := DllCall("MonitorFromPoint" , "int64", 0 ; point on monitor , "uint", 1) ; flag to return primary monitor on failure ; Get Physical Monitor from handle VarSetCapacity(Physical_Monitor, 8 + 256, 0) DllCall("dxva2\GetPhysicalMonitorsFromHMONITOR" , "int", hMon ; monitor handle , "uint", 1 ; monitor array size , "int", &Physical_Monitor) ; point to array with monitor return hPhysMon := NumGet(Physical_Monitor) } destroyMonitorHandle(handle) { DllCall("dxva2\DestroyPhysicalMonitor", "int", handle) } ; 更改显示器输入源函数 ; Used to change the monitor source setMonitorInputSource(source) { handle := getMonitorHandle() DllCall("dxva2\SetVCPFeature" , "int", handle , "char", 0x60 ;VCP code for Input Source Select , "uint", source) destroyMonitorHandle(handle) } ; 获取显示器输入接口id函数 ; Gets Monitor source getMonitorInputSource() { handle := getMonitorHandle() DllCall("dxva2\GetVCPFeatureAndVCPFeatureReply" , "int", handle , "char", 0x60 ;VCP code for Input Source Select , "Ptr", 0 , "uint*", currentValue , "uint*", maximumValue) destroyMonitorHandle(handle) return currentValue } ; BenQ ew2770qz 输入接口id ; dp=16=10H=0x10 ; hdmi1=17=11H=0x11 ; hdmi2=18=12H=0x12 ; AOC U2790PQU 输入接口id ; dp=15=0fH=0x0f ; hdmi1=17=11H=0x11 ; hdmi2=18=12H=0x12 ; 设置快捷键win+z, 获取显示器输入接口id ; Get sources~id #z:: MsgBox, % getMonitorInputSource() return ; 设置快捷键win+x, 切换dp输入源 ; Switching sources~dp #x:: ;to dp setMonitorInputSource(0x0f) return ; 设置快捷键win+c, 切换hdmi 1输入源 ; Switching sources~hdmi1 #c:: ;to hdmi1 setMonitorInputSource(0x11) return ; 设置快捷键win+v, 切换hdmi 2输入源 ; Switching sources~hdmi2 #v:: ;to hdmi2 setMonitorInputSource(0x12) return 获取你的显示器的输入源id右击你的ahk脚本,使用Auto Hot Key打开运行。 按下win+z获取显示器当前输入源id: 15是十进制id,其16进制为0fH,我们更改脚本时参数要输入为0x0f setMonitorInputSource(0x0f)其他输入源的id我们可以手动切换显示器输入源,然后盲按win+z键获取id,接着切换回windows就可以拿到其他输入源id了。 编译成.exe可执行文件打开Convert .ahk to .exe 选择你的ahk脚本,点击下方Convert即可编译成.exe可执行文件,可以在其他没有安装Auto Hot Key的电脑上直接运行。 |
CopyRight 2018-2019 实验室设备网 版权所有 |