PCDVD數位科技討論區
PCDVD數位科技討論區   註冊 常見問題 標記討論區為已讀

回到   PCDVD數位科技討論區 > 數位影音討論群組 > 顯示設備討論區
帳戶
密碼
 

  回應
 
主題工具
edwardliu
Advance Member
 
edwardliu的大頭照
 

加入日期: Dec 2002
文章: 466
【圖文】AutoHotKey快速切換<螢幕輸入源>

前一陣子左眼發生視網膜裂孔,才覺得工作的用眼環境或許不是很好。

本來工作用兩台筆電。
一個14吋NB主要收信看信,有外接LCD 24吋,斜放在桌面右前方。
一個15吋NB放正前方工作。
15吋FHD看字有點吃力,骨董LCD 24吋是斜放著,偏光膜已雪花片片,想想對眼睛應該都不好。
另外有了小孩都得準時下班接小孩,中午時間也利用來工作,即使辦公室強制關燈休息一小時。

於是農曆過年期間就去家樂福搬了BenQ GC2870+Wit ScreenBar,打算對眼睛好一點。
現在兩台筆電都用HDMI接上28吋LCD,Keyboard/Mouse一直以來是透過J5create的資料傳輸線共用,按一下"Alt+S"就可以在兩台電腦間切換使用。


剩下的問題就是切換HDMI1和HDMI2啦。
BenQ的快捷鍵一點也不快捷,要換4~5下按鈕才能完成(我來設計的話最多按兩下完成,這才堪用吧?)。

Step1: 按下2號鍵,顯示各鍵功能。


Step2: 按下2號鍵,進入訊源選單。


Step3: 按下2號鍵,選擇HDMI2。


Step4: 按下3號鍵,確認切換HDMI2。


完成


實在是費時、費神、螢幕還會晃。

所幸顯示器有支援DDC/CI,可以透過軟體去實現切換。
這邊找到的是AutoHotkey這個軟體,我也是第一次用,摸索了一下。
可能有這個需求的人也不多,但希望可以幫到人。

主要內容參考Google來的文章: https://www.reddit.com/r/AutoHotkey...her_ahk_forums/

下載AutoHotkey並安裝(快速安裝即可)


在"文件"資料夾建立AutoHotkey.ahk文字檔(沒有這個script檔,執行時只會出現help說明檔)


文字檔輸入以下文字,這個Script是透過"Alt+R"鍵,來回傳monitor handle的值(目前輸入源)。
代碼:
; Finds monitor handle
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)
}

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
}

;~ : Used to set the monitor source, I do not know what happens if you send it a value higher than the maximum.
;~ setMonitorInputSource(source)
{
  handle := getMonitorHandle()
DllCall("dxva2\SetVCPFeature"
  , "int", handle
  , "char", 0x60 ;VCP code for Input Source Select
  , "uint", source)
destroyMonitorHandle(handle)
}  


; Msgbox with current monitor input source
!r::
msgbox % getMonitorInputSource()
return


前置作業: 開啟DDC/CI


前置作業: HDMI auto (非必要?)


前置作業: 將電腦輸出到 HDMI only (若是設"同步顯示"回傳值都是為0)


開啟AutoHotkey


在HDMI1時,按下Alt+R讀取目前monitor handle (Alt+R是我亂試的,我還沒研究script語法@@)


手動切換到HDMI2,按下Alt+R。
再手動切回HDMI1,記錄回傳值。
GC2870 回傳 HDMI1=17, HDMI2=18 (十進位)

修改 Script


刪除原來的所有內容,輸入以下(文章說要用十六進位輸入,請自行注意)
代碼:
; Finds monitor handle
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
; [BenQ] GC2870
;   D-Sub = ?
;   HDMI1 = 17 (0x11)
;   HDMI2 = 18 (0x12)
setMonitorInputSource(source)
{
  handle := getMonitorHandle()
  DllCall("dxva2\SetVCPFeature"
  , "int", handle
  , "char", 0x60 ;VCP code for Input Source Select
  , "int", source)
destroyMonitorHandle(handle)
}

; 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
}

;~ #IfWinActive
Pause::
if(getMonitorInputSource() != 0x11) ;if not HDMI1
  setMonitorInputSource(0x11) ;switch to HDMI1
else
  setMonitorInputSource(0x12) ;else switch to HDMI2
return


重新載入(或關閉程式,再重執行)


之後就按 Pause 鍵就可以快速切換 HDMI1/HDMI2 啦啦啦啦啦啦啦

# 完畢 #
     
      
舊 2019-02-20, 04:06 PM #1
回應時引用此文章
edwardliu離線中  
Xmeck
Basic Member
 

加入日期: May 2015
文章: 13
最近剛好有用ahk自訂鍵盤快速鍵

!r:: ; alt + r
Pause:: ;pause

可以把訊號切換跟週邊設一樣
 
舊 2019-02-27, 04:25 AM #2
回應時引用此文章
Xmeck離線中  
momomo
Major Member
 
momomo的大頭照
 

加入日期: Nov 2000
您的住址: 1又1/2樓
文章: 101
訂閱一下, 也許哪天可以派上用場
__________________
いつも思ってたことがあるの
人が周りにいないからじゃなくて、自分をわかってくれる人がいないから、寂しくなるんだね

高校教師∼僕たちの失敗∼より
舊 2019-03-11, 06:01 PM #3
回應時引用此文章
momomo離線中  
Kia ora
Basic Member
 

加入日期: Feb 2015
文章: 22
看起來好像很厲害.....
舊 2019-03-12, 06:34 PM #4
回應時引用此文章
Kia ora離線中  
carlhong
Amateur Member
 

加入日期: Sep 2001
文章: 45
謝謝分享 訂閱一下 也許之後會用到
舊 2019-09-14, 06:09 AM #5
回應時引用此文章
carlhong離線中  
ksw03
Major Member
 

加入日期: Jan 2002
文章: 176
個人也有相關需求,搜尋找到一個螢幕資訊小工具程式control_my_monitor:
https://www.nirsoft.net/utils/control_my_monitor.html
舊 2019-09-30, 07:12 AM #6
回應時引用此文章
ksw03離線中  
ksw03
Major Member
 

加入日期: Jan 2002
文章: 176
另外也找到了一個 ACER EB321HQU現成可用的腳本 https://moshen.net/posts/virtual_kvm/
切換下個輸入:CTRL+ALT + ] 返回 CTRL+ALT + [
舊 2019-09-30, 07:47 AM #7
回應時引用此文章
ksw03離線中  
vchou
Golden Member
 
vchou的大頭照
 

加入日期: Mar 2002
您的住址: High Male
文章: 3,966
AutoHotKey 我上班打報告用了十幾年了, 超好用的啦
舊 2019-09-30, 11:30 PM #8
回應時引用此文章
vchou離線中  
PM
Power Member
 
PM的大頭照
 

加入日期: Sep 2006
文章: 539
有找到一個可以直接設hotkey送DDC/CI控制碼的程式
https://www.clickmonitorddc.bplaced.net/

Autohotkey要自己抓碼不是很直覺, 這個只要設熱鍵, 下指令就行了
設定要自己改一下, 不然系統列會多一堆icon
舊 2019-10-06, 07:23 PM #9
回應時引用此文章
PM離線中  
edwardliu
Advance Member
 
edwardliu的大頭照
 

加入日期: Dec 2002
文章: 466
【新增】AutoHotKey快速調整<螢幕亮度>

有一點空檔,又來研究用熱鍵設定"外接螢幕"的亮度。

當然是撿現成的來用,參考
https://www.autohotkey.com/boards/v...8218b340f44767c

先加入 source code 部份

再加上設定亮度的語法 - 參考 "Sets a (particular) monitor's brightness value." 說明

一樣還是利用沒人要的"Pause"鍵
讓 Shift+Pause 將螢幕亮度在 45 和 8 之間變換

這樣中午辦公室關燈,調整亮度就更方便了。

#完畢#

此文章於 2020-11-24 04:31 PM 被 edwardliu 編輯.
舊 2020-11-24, 04:30 PM #10
回應時引用此文章
edwardliu離線中  


    回應


POPIN
主題工具

發表文章規則
不可以發起新主題
不可以回應主題
不可以上傳附加檔案
不可以編輯您的文章

vB 代碼打開
[IMG]代碼打開
HTML代碼關閉



所有的時間均為GMT +8。 現在的時間是12:35 AM.


vBulletin Version 3.0.1
powered_by_vbulletin 2024。