DeviceIDPnP icon indicating copy to clipboard operation
DeviceIDPnP copied to clipboard

Not detecting HDMI connection properly.

Open codychen98 opened this issue 1 year ago • 2 comments

Thank you for the script, it's a huge lifesaver for my use case with KVM switch, I encounter some issues and I'd appreciate any help.

I'm currently using version 1.2.0 for AutoHotkey 1.0 from your commit history, and I have HDMI monitor hooked up to a KVM switch to my main PC and work laptop. The idea is that if I switch KVM with hotkey, it will disconnect the HDMI monitor from my main PC, and then it should switch video signals to my laptop. If I switch KVM with hotkey again, it will connect the HDMI monitor back to my main PC, and switch the signal to my main PC.

I'm stuck on detecting the connection status, when I connect the HDMI monitor, it says connected, and then disconnected even though it's still plugged in. When I disconnect the HDMI monitor, it says disconnected and nothing else. Which is correct. Do you have any ideas on what could be the issue? Thanks!

oMyDevices := {}
oMyDevices.Push({"DeviceName":"Generic Monitor (HDMI)", "DeviceID":"DISPLAY\XXX0133\5&707AA03&2&UID45312"})

DevicesActions(ThisDeviceStatusHasChanged) {

    If (ThisDeviceStatusHasChanged = "Generic Monitor (HDMI) Connected")
            voice := ComObjCreate("SAPI.SpVoice")
            ;voice.rate := -10
            voice.volume := 100
         voice.Speak("Connected")

    If (ThisDeviceStatusHasChanged = "Generic Monitor (HDMI) Disconnected")
            voice := ComObjCreate("SAPI.SpVoice")
            ;voice.rate := -10
            voice.volume := 100
         voice.Speak("Disconnected")

Below is the list of DeviceID from DeviceIDFinder.ahk when toggling KVM switch

HID-compliant consumer control device:
HID\VID_046D&PID_C539&MI_01&COL02\E&48D3944&0&0001

HID-compliant mouse:
HID\VID_046D&PID_C539&MI_01&COL01\E&48D3944&0&0000

Microphone (FIFINE K678 Microphone):
SWD\MMDEVAPI\{0.0.1.00000000}.{5F8FF0C5-DD7E-4FC7-B90B-C3C9EE0F24F5}

USB Input Device:
USB\VID_046D&PID_C539&MI_02\D&2A09E01C&0&0002

HID-compliant headset:
HID\VID_3142&PID_0002&MI_03&COL02\8&25C062B9&0&0001

USB Input Device:
USB\VID_3142&PID_0002&MI_03\7&665864A&0&0003

Generic USB Hub:
USB\VID_214B&PID_7250\B&3A944CE5&0&2

HID-compliant vendor-defined device:
HID\VID_046D&PID_C539&MI_02&COL01\E&1F4A047E&0&0000

FIFINE K678 Microphone:
USB\VID_3142&PID_0002&MI_00\7&665864A&0&0000

G502 LIGHTSPEED:
USB\VID_046D&PID_C539&LAMPARRAY\D&2A09E01C&0&4_SLOT00

LIGHTSPEED Receiver:
USB\VID_046D&PID_C539&LAMPARRAY\D&2A09E01C&0&4_SLOT01

LIGHTSPEED Receiver:
USB\VID_046D&PID_C539&LAMPARRAY\D&2A09E01C&0&4_SLOT02

LIGHTSPEED Receiver:
USB\VID_046D&PID_C539&LAMPARRAY\D&2A09E01C&0&4_SLOT03

LIGHTSPEED Receiver:
USB\VID_046D&PID_C539&LAMPARRAY\D&2A09E01C&0&4_SLOT04

LIGHTSPEED Receiver:
USB\VID_046D&PID_C539&LAMPARRAY\D&2A09E01C&0&4_SLOT05

LIGHTSPEED Receiver:
USB\VID_046D&PID_C539&LAMPARRAY\D&2A09E01C&0&4_SLOT06

Generic Monitor (HDMI):
DISPLAY\XXX0133\5&707AA03&2&UID45312

USB Billboard Device   :
USB\VID_2109&PID_8817\0000000000000001

HID-compliant vendor-defined device:
HID\VID_046D&PID_C539&MI_02&COL02\E&1F4A047E&0&0001

G502 LIGHTSPEED:
USB\VID_046D&PID_C539\C&F49C187&0&4

Generic SuperSpeed USB Hub:
USB\VID_2109&PID_0817\MSFT30000000000

HID-compliant vendor-defined device:
HID\VID_046D&PID_C539&MI_02&COL03\E&1F4A047E&0&0002

HID Keyboard Device:
HID\VID_046D&PID_C539&MI_00\E&28647706&0&0000

USB Input Device:
USB\VID_046D&PID_C539&MI_00\D&2A09E01C&0&0000

Generic USB Hub:
USB\VID_2109&PID_2817\MSFT20000000000

USB Input Device:
USB\VID_046D&PID_C539&MI_01\D&2A09E01C&0&0001

USB Composite Device:
USB\VID_3142&PID_0002\REV1.0

HID-compliant consumer control device:
HID\VID_3142&PID_0002&MI_03&COL01\8&25C062B9&0&0000

HID-compliant vendor-defined device:
HID\VID_046D&PID_C539&MI_01&COL04\E&48D3944&0&0003

HID-compliant system controller:
HID\VID_046D&PID_C539&MI_01&COL03\E&48D3944&0&0002

codychen98 avatar Mar 11 '24 15:03 codychen98

Enclose the Control Flow Statements (if, etc.) in braces (code block).

https://www.autohotkey.com/docs/v2/Language.htm#control-flow

If any of the control flow statements have only a single statement, that statement need not be enclosed in a block.

https://www.autohotkey.com/docs/v2/lib/Block.htm

DevicesActions(ThisDeviceStatusHasChanged) {

	If (ThisDeviceStatusHasChanged = "Generic Monitor (HDMI) Connected") {
		voice := ComObjCreate("SAPI.SpVoice")
		;voice.rate := -10
		voice.volume := 100
		voice.Speak("Connected")
	}

	If (ThisDeviceStatusHasChanged = "Generic Monitor (HDMI) Disconnected") {
		voice := ComObjCreate("SAPI.SpVoice")
		;voice.rate := -10
		voice.volume := 100
		voice.Speak("Disconnected")
	}
}

MCxQC avatar Mar 11 '24 16:03 MCxQC

Enclose the Control Flow Statements (if, etc.) in braces (code block).

https://www.autohotkey.com/docs/v2/Language.htm#control-flow

If any of the control flow statements have only a single statement, that statement need not be enclosed in a block.

https://www.autohotkey.com/docs/v2/lib/Block.htm

DevicesActions(ThisDeviceStatusHasChanged) {

	If (ThisDeviceStatusHasChanged = "Generic Monitor (HDMI) Connected") {
		voice := ComObjCreate("SAPI.SpVoice")
		;voice.rate := -10
		voice.volume := 100
		voice.Speak("Connected")
	}

	If (ThisDeviceStatusHasChanged = "Generic Monitor (HDMI) Disconnected") {
		voice := ComObjCreate("SAPI.SpVoice")
		;voice.rate := -10
		voice.volume := 100
		voice.Speak("Disconnected")
	}
}

Thank you SO MUCH, I finally made it work! Again, I really appreciate your script, have a great day!

codychen98 avatar Mar 11 '24 16:03 codychen98