I just did this very thing recently by adding a record to the Keyboard Inputs plugin and using that to trigger the action through the screen PLC script. My thanks to DazTheGas as I figured this out after watching his 'Mach4 Quicky #2 Keyboard Plugin' video:
https://youtu.be/yzaf5pT0l501) Assign functions to keys:
Configure->Plugins->Keyboard_Inputs
Add input
InputName: EnableMach
Key: E (for Enable)
CTRL+ALT+SHIFT all checked so that this is not going to happen by accident
Lock key: none
Function: none
I also added similar Inputs for DisableMach (D key), StartCycle (S), HaltCycle (H, because S was already taken and I didn't want to use it as a toggle), and ResetCycle (R).
2)Map the keyboard inputs to Mach inputs:
Configure->Control->Inputs Signals
Input #6 (only because it was the next one available after several of my ESS inputs)
Mapping Enabled: checked
Device: keyboard (from dropdown)
Input Name: EnableMach (from dropdown)
I repeated above using Inputs #7-10 for DisableMach, StartCycle, HaltCycle, and ResetCycle respectively.
3) Add the following code to the screen PLC script immediately following the end of the 'PLC First Run' section:
-------------------------------------------------------
--PE3696 ENABLE Mach: CTRL+ALT+SHIFT+E[nable]
-------------------------------------------------------
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT6)) == 1 then
mc.mcCntlEnable(inst,1)
else
-- Do something else
end
-------------------------------------------------------
--PE3696 DISABLE Mach: CTRL+ALT+SHIFT+D[isable]
-------------------------------------------------------
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT7)) == 1 then
mc.mcCntlEnable(inst,0)
else
-- Do something else
end
-------------------------------------------------------
--PE3696 START CYCLE: CTRL+ALT+SHIFT+S[tart]
-------------------------------------------------------
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT8)) == 1 then
mc.mcCntlCycleStart (inst)
else
-- Do something else
end
-------------------------------------------------------
--PE3696 STOP CYCLE: CTRL+ALT+SHIFT+H[alt]
-------------------------------------------------------
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT9)) == 1 then
mc.mcCntlCycleStop (inst)
else
-- Do something else
end
-------------------------------------------------------
--PE3696 RESET CYCLE: CTRL+ALT+SHIFT+R[eset]
-------------------------------------------------------
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT10)) == 1 then
mc.mcCntlCycleStop (inst)
mc.mcCntlReset (inst)
else
-- Do something else
end
You will have to enable Keyboard Inputs on the Jogging Tab. You can do this automatically at Mach startup by adding the following code inside the end of the 'PLC First Run' section of the screen PLC script:
-------------------------------------------------------
--PE3696 Enable Keyboard on startup
-------------------------------------------------------
local hKeyboardState = mc.mcRegGetHandle(inst, "KeyboardControl/Enabled");
local KeyboardState = mc.mcRegGetValue(hKeyboardState);
if (KeyboardState == 0) then;
KeyboardInputsToggle()
else;
--Do something else
end;
This may be a primitive way of accomplishing all of these actions but it works for me. I'm new to Lua and Mach4, so please tell me if this method is risky or if there is a vastly simpler way of doing it.
-Paul