My objective is to create a script that opens a relay on key press down, and closes on key up. Works on all keyboard keys and not mouse. The idea is the relay is like a keyboard solenoid/clicker that opens and closes based on key down and up.
I modified a script based off Rohwedder which works mostly but cant differentiate between key press down or up so i can open or close the relay separately.
Any idea what the best way to do this would be? I still want the keyboard to continue doing keyboard things but just simply open a relay and keypress down and close relay on keypress release. Is there a modification of this code that can be done or does it need to be done from scratch?
The code simply sends the bytes using SerialSend.exe to activate the LCUS-1 USB relay.
Code: Select all
;code from Rohwedder (https://www.autohotkey.com/boards/viewtopic.php?style=17&f=76&t=77075)
Gui, +HwndGui
Gui, Add, Edit, vMyEdit
Gui, Show
Format := "SC{:X}"
Loop, 0x1FF
Gosub, TestEndkey
Format := "VK{:X}"
Loop, 0xFF
Gosub, TestEndKey
Gui, Destroy
Loop
{
ih := InputHook("L1 M V", EndKeys)
ih.Start(), ih.Wait()
;Runs software SerialSend to communicate with LCUS-1 over com port 3 with baudrate of 9600.
;relay on
run,SerialSend /devnum 9 /baudrate 9600 /hex "\xA0\x01\x01\xA2",,Hide
;delay
sleep, 10
;relay off
run,SerialSend /devnum 9 /baudrate 9600 /hex "\xA0\x01\x00\xA1",,Hide
}
Return
TestEndKey:
IF ("" = Key := GetKeyName(Format(Format, A_Index)))
Or InStr(Key, "Button") Or InStr(Key, "Wheel")
Return
ControlSend, Edit1,% Key := "{" Key "}", ahk_id %Gui%
Gui, Submit
IF (MyEdit = "") And !Instr(EndKeys, Key)
EndKeys .= Key
ControlSend, Edit1, {Bs}, ahk_id %Gui%
Return
Let me know if you have any more questions.