Ok, but all those things are controlled by the mission author, right?
Only if the mission is never run with any addons (well, OK, SPON Kits, for example, is a mission-script so yes, that is under the control of the mission maker). Any of which could mess you up
Oh, just remembered that when you press any button, you continually get DOWN events being called. Like I said, really telling if the NVG is on or off this way is more complex than it appears and is pretty much guaranteed to fail as soon as the average player tries to use it (players always find the best way to break anything, even if, as a dev you would never think of it)!
Sorry, had a brain fart moment originally (And wasn't writing in SQF or remembering what the hell I was doing!):
nightvision_keyDown =
{
// Either key up has been lost in a disableKeyEvents/dialog entry or the
// key has been recorded as released properly via up event.
if ((time - irBeacon_downAt) > 1) then
{
irBeacon_brightness = if (irBeacon_brightness == 0) then { 0.05 } else { 0 };
};
irBeacon_downAt = time;
false; // Must return false, otherwise other handlers won't be informed of the event.
};
nightvision_keyUp =
{
irBeacon_downAt = 0; // Key has been released, so record presses again.
false; // Must return false, otherwise other handlers won't be informed of the event.
};
{
["Down", _x, nightvision_keyDown] call SPON_addKeyEventHandler;
["Up", _x, nightvision_keyUp] call SPON_addKeyEventHandler;
} forEach actionKeys "nightVision";
Still, you'll have critical problems with, for example, the popular manual NVG addon.