Created
January 25, 2024 18:00
-
-
Save vilicvane/8ca2587848b8e701f8f69a61de23b36d to your computer and use it in GitHub Desktop.
Active Mouse Monitor Input Select Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {spawn} from 'child_process'; | |
const CONTROL_MY_MONITOR_PATH = | |
'C:\\Utilities\\controlmymonitor\\ControlMyMonitor.exe'; | |
const MONITORS = ['JPKRZG3', '6ZWV123']; | |
const MONITOR_INPUTS_DICT = { | |
'vane-station': [15, 15], | |
'vane-mbp': [27, 27], | |
}; | |
const INPUT_SELECT_CODE = '60'; | |
const CHECK_INTERVAL = 5000; | |
let timer; | |
export default { | |
type: 'server', | |
name: 'vane-station', | |
action(name) { | |
clearInterval(timer); | |
const inputs = MONITOR_INPUTS_DICT[name]; | |
selectInputs(); | |
timer = setInterval(() => selectInputs(), CHECK_INTERVAL); | |
function selectInputs() { | |
for (const [index, monitor] of MONITORS.entries()) { | |
selectInputIfNeeded(monitor, inputs[index]); | |
} | |
} | |
}, | |
}; | |
function selectInputIfNeeded(monitor, expected) { | |
spawn(CONTROL_MY_MONITOR_PATH, ['/GetValue', monitor, INPUT_SELECT_CODE]).on( | |
'exit', | |
code => { | |
const actual = code & 0xff; | |
if (actual === 0 || actual === expected) { | |
return; | |
} | |
console.log({actual, expected}); | |
spawn(CONTROL_MY_MONITOR_PATH, [ | |
'/SetValue', | |
monitor, | |
INPUT_SELECT_CODE, | |
expected, | |
]); | |
}, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment