repeats / Repeat

Cross-platform mouse/keyboard record/replay and automation hotkeys/macros creation, and more advanced automation features.
Apache License 2.0
1.03k stars 76 forks source link

Is it possible to activate/deactivate macros based on a lock state #50

Open BeegMan27 opened 3 months ago

BeegMan27 commented 3 months ago

I'm not totally sure if this is the right way to ask a question like this, but I found that the existing documentation was not specific enough to be helpful in this case.

I want to create a script/macro/task/whatever-tf-it's-called that uses the scroll lock key to toggle the numpad between normal functionality and a 'macro mode'. This is to say, while scroll lock is inactive, the numpad acts as normal and while active, each key sends an 'F#' key or other custom keystroke combination. Is this kind of thing supported?

hptruong93 commented 3 months ago

There's a Java code (seemingly only works in Windows) to detect whether Scroll Lock is activated.

Check this answer on Stackoverflow https://stackoverflow.com/a/7435344/1974520. So you could just write a precondition at the start of the task.

boolean isOn = java.awt.Toolkit.getDefaultToolkit().getLockingKeyState(java.awt.event.KeyEvent.VK_NUM_LOCK);
if (!isOn) {
  return;
}

Another way is to create a 2nd task, and have that task be activated on ScrollLock, then use a variable to store the state of the scroll lock (assuming it's off as a starting state). Then the main task can read that shared variable to retrieve the state of the scroll lock. Let me know if that's clear or you'd want some code for this 2nd option.