In Mach 4, it is better not to think of buttons that do things. To implement something that a button AND a key press does, it is better to define the action in the screen script and have both the button and key press call that script function. That way, you are not duplicating code and when you make changes, you make them in one place.
So in the PLC script:
function mySuperFunc
-- A script function that does what I want.
...
end
Then, in the button Left Up scritp:
mySuperFunc();
Then, using the keyboard plugin, you map a key to an named input. At this point, you have two options:
1. Look at that input in the PLC script directly using mcIoGetHandle() and mcIoGetState() directly. However, it is hard to catch a momentary push this way.
or
2. Map the I/O to and input signal and catch the state change in the screen signals script.
I prefer method 2.
So map the keypord input to say Mach Input signal Input#1. Then in the screen signal script do:
local inst = mc.mcGetInstance();
if (sig == mc.ISIG_INPUT1) then
if (state == 1) then
mySuperFunc();
end
end
Steve