[AHK]--显示器输入源快速切换
顯示器輸入源快速切換
- 前言
- DDC/CI 協(xié)議簡介
- Auto Hot Key簡介
- 顯示器輸入源快捷鍵切換ahk腳本代碼
- 獲取你的顯示器的輸入源id
- 編譯成.exe可執(zhí)行文件
前言
當(dāng)你有多臺設(shè)備需要共用一臺顯示器,這個(gè)時(shí)候通過顯示器物理按鍵頻繁切換顯示器輸入源就會(huì)比較麻煩。如果我們可以通過快捷鍵的方式切換的話,將會(huì)方便不少。
本文將介紹如何在windows環(huán)境下使用ahk腳本實(shí)現(xiàn)顯示器輸入源快捷鍵切換。
參考資料:https://www.chiphell.com/thread-2248082-1-1.html
DDC/CI 協(xié)議簡介
DDC/CI協(xié)議是Display Data Channel Command Interface的簡稱?;贒DC/CI協(xié)議,用戶可以通過鼠標(biāo)和人性化的軟件界面來完成顯示器的各項(xiàng)設(shè)置和色彩調(diào)節(jié),而不必使用傳統(tǒng)的OSD菜單。
以上簡介來自百度百科,其實(shí)DDC/CI協(xié)議說白了就是可以讓我們連接顯示器的設(shè)備與顯示器之間進(jìn)行通信,方便我們調(diào)節(jié)顯示器的設(shè)置。
本文所介紹的顯示器輸入源快速切換的方法需要你的顯示器支持DDC/CI協(xié)議,請確保你的顯示器支持該協(xié)議并打開該設(shè)置。
Auto Hot Key簡介
Auto Hot Key是一款免費(fèi)的、Windows下開源的熱鍵腳本語言。也可以通過命令調(diào)用系統(tǒng)接口及程序,并創(chuàng)建基于簡單語言的圖形化界面的執(zhí)行程序。
官網(wǎng)地址:Auto Hot Key
如果你的電腦沒有安裝Auto Hot Key,你可以訪問以上官網(wǎng)進(jìn)行下載安裝。
顯示器輸入源快捷鍵切換ahk腳本代碼
首先新建一個(gè).ahk文件。
然后在該文件中寫入以下代碼:
(其中切換各個(gè)輸入源的id需要你根據(jù)你自己的顯示器去更改,以下是適用于aoc u2790pqu顯示器的ahk腳本,我還測試了benq ew2770qz顯示器,也可以使用)
; 函數(shù)getMonitorHandle()和destroyMonitorHandle(handle)涉及到windows編程,本人水平有限,沒弄懂如何編寫,只會(huì)使用,感興趣的可以自己看看英文原注釋 ; Finds monitor handle based on MousePosition getMonitorHandle() {; Initialize Monitor handlehMon := DllCall("MonitorFromPoint", "int64", 0 ; point on monitor, "uint", 1) ; flag to return primary monitor on failure; Get Physical Monitor from handleVarSetCapacity(Physical_Monitor, 8 + 256, 0)DllCall("dxva2\GetPhysicalMonitorsFromHMONITOR", "int", hMon ; monitor handle, "uint", 1 ; monitor array size, "int", &Physical_Monitor) ; point to array with monitorreturn hPhysMon := NumGet(Physical_Monitor) }destroyMonitorHandle(handle) {DllCall("dxva2\DestroyPhysicalMonitor", "int", handle) }; 更改顯示器輸入源函數(shù) ; 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函數(shù) ; 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; 設(shè)置快捷鍵win+z, 獲取顯示器輸入接口id ; Get sources~id #z:: MsgBox, % getMonitorInputSource() return; 設(shè)置快捷鍵win+x, 切換dp輸入源 ; Switching sources~dp #x:: ;to dp setMonitorInputSource(0x0f) return; 設(shè)置快捷鍵win+c, 切換hdmi 1輸入源 ; Switching sources~hdmi1 #c:: ;to hdmi1 setMonitorInputSource(0x11) return; 設(shè)置快捷鍵win+v, 切換hdmi 2輸入源 ; Switching sources~hdmi2 #v:: ;to hdmi2 setMonitorInputSource(0x12) return獲取你的顯示器的輸入源id
右擊你的ahk腳本,使用Auto Hot Key打開運(yùn)行。
按下win+z獲取顯示器當(dāng)前輸入源id:
15是十進(jìn)制id,其16進(jìn)制為0fH,我們更改腳本時(shí)參數(shù)要輸入為0x0f
setMonitorInputSource(0x0f)其他輸入源的id我們可以手動(dòng)切換顯示器輸入源,然后盲按win+z鍵獲取id,接著切換回windows就可以拿到其他輸入源id了。
編譯成.exe可執(zhí)行文件
打開Convert .ahk to .exe
選擇你的ahk腳本,點(diǎn)擊下方Convert即可編譯成.exe可執(zhí)行文件,可以在其他沒有安裝Auto Hot Key的電腦上直接運(yùn)行。
總結(jié)
以上是生活随笔為你收集整理的[AHK]--显示器输入源快速切换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 利用Contacts Provider读
- 下一篇: 常用的 T-SQL 语言