Hello Guest it is April 26, 2024, 06:21:24 AM

Author Topic: Way in lua to know if mach4 is minimized or not.  (Read 707 times)

0 Members and 1 Guest are viewing this topic.

Way in lua to know if mach4 is minimized or not.
« on: February 28, 2022, 04:07:17 PM »
Hi again folks,
                    i searched in the api manuel and did'nt find what i want, is there a way to see in lua if mach4 is minimized or not so i can activate the keyboard plugin if mach4 screen is there and desactivate it when minimized.
Thanks in advance
Re: Way in lua to know if mach4 is minimized or not.
« Reply #1 on: February 28, 2022, 09:45:09 PM »
Hi,
what is it you are trying to do? To activate or de-activate the Keyboard plugin requires a restart of Mach, so I would not of thought that was helpful.

If you are just trying to disable Keyboard jogging when Mach is minimised then I would run a script that disables the buttons individually rather than de-activating
the whole plugin.
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Way in lua to know if mach4 is minimized or not.
« Reply #2 on: February 28, 2022, 09:51:49 PM »
Hi,
    thanks for your reply, sorry my mistake, all i want is a signal from mach4 to trigger when it is minimized or showed, with that i could make a script that enable or disable the keybord.
Re: Way in lua to know if mach4 is minimized or not.
« Reply #3 on: March 02, 2022, 06:41:13 AM »
The keyboard plugin has outputs that you can map to a Mach4 output. See attached image.  There is two options, one to disable keyboard, and another to disable keyboard inputs completely.

There is also a scr API call to return the window title which you can monitor in the PLC script and then if it does not equal the whatever is shown at the top of your window you can turn off the output.
Code: [Select]
scr.GetActiveWindowText()

Ok, I've ended up doing it for you  ;D Just drop this in your PLC script. You will need to check the mapping of the keyboard enable in the outputs and modify the code. Also the search term "Mach 4" can be changed depending what is shown at the top of your window.

Code: [Select]
local windowText = scr.GetActiveWindowText() --Get the window title text
local find = string.find(windowText, "Mach 4") --Search for "Mach 4" in the window title.
local hKeyboardOutput = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
local keyboardOutputState = mc.mcSignalGetState(hKeyboardOutput)
if find ~= nil then
--"Mach 4" was found i.e. Window is active
if (keyboardOutputState == mc.MC_OFF) then --Only turn on the output if it is off
mc.mcSignalSetState(hKeyboardOutput, mc.MC_ON)
end
else
--"Mach 4" was not found i.e. window minimised or lost focus
if (keyboardOutputState == mc.MC_ON) then--Only turn off the output if it is on
mc.mcSignalSetState(hKeyboardOutput, mc.MC_OFF)
end
end



Re: Way in lua to know if mach4 is minimized or not.
« Reply #4 on: March 02, 2022, 06:20:58 PM »
Thanks  SwiftyJ,
                        you give me a lot more then what i asked lol, so appreciated. work like a charm.