Mouse jiggler macro

I have a heavilly locked down Windows machine which is set to sleep after 1 minute of inactivity which is impossible to work on.

I’d like to create a macro for UHK that jiggles the mouse indefinately until MOD key is hit again. If this possible in any way with UHK? Like a macro with a for loop.

Yes, definitely possible with macro commands, although possibly a bit complicated. See firmware/doc-dev/user-guide.md at master · UltimateHackingKeyboard/firmware · GitHub and firmware/doc-dev/reference-manual.md at master · UltimateHackingKeyboard/firmware · GitHub

Something like:

setVar stopJiggler 0
if ($jigglerActive) break
setVar jigglerActive 1
loop:
<gui action to move mouse one pixel right>
<gui action to move mouse one pixel left>
delayUntil 50000
if ($stopJiggler) {
    setVar stopJiggler 0
    setVar jigglerActive 0
    break
}
goTo loop

And a macro to stop it:

setVar stopJiggler 1
2 Likes

This is the most amusing use case ever! :smiley:

That worked perfectly. Thank you!! :smiley:

Is there any way to activate and deactivate the script together with the status of Caps Lock? That way i’d have a “status symbol” showing when its active and not. I never use caps lock anyways :sweat_smile:

If you mean to steal the caps lock led for showing the status of the jiggler without actually activating caps lock, then no. What you can do is to override a per-key-RGB color of a specific key to show the status with set backlight.keyRgb.LAYERID.KEYID <number 0-255 (INT)> <number 0-255 (INT)> <number 0-255 (INT)>

Otherwise you sure can ifNotCapsLockOn tapKey capsLock at the beginning of the macro and ifCapsLockOn tapKey capsLock in the exit block.

If you mean you want to trigger it by caps lock state, then you can use the $onCapsLockStateChange macro event.

It’s a very useful use case. I have something for that too.

I created a keymap --- which when selected pushes the mouse around a little bit while displaying an animation on the LED display. So that’s how I can see whether it’s currently active.

The keymap is a copy of my normal keymap but runs the command call keepAlive in its $onKeymapChange --- macro.

One key Fn-ISO on my normal keymap switches to this keymap, and the same key Fn-ISO on the --- keymap switches back to my normal keymap. So I can use this key to toggle between mouse jiggling on/off.

The keepAlive macro pretty much looks like this:

setVar r 6
startloop:
ifKeymap --- setLedTxt 200 "`-'"
ifKeymap --- setLedTxt 200 "---"
ifKeymap --- repeatFor r startloop
keepalive:

A “moveMouse” command with “x”: 3, “y”: 0 (right 3 pixels)

ifNotKeymap --- goTo final
ifKeymap --- setLedTxt 200 "---"
ifKeymap --- setLedTxt 200 "}--"
ifKeymap --- setLedTxt 200 "-}-"
ifKeymap --- setLedTxt 200 "--}"

Then a “moveMouse” command with “x”: 0, “y”: 1 (down 1 pixel)

ifNotKeymap --- goTo final

Then a “delay” command with “delay”: 2000.
Then a “moveMouse” command with “x”: -3, “y”: 0 (left 3 pixels).

ifNotKeymap --- goTo final
ifKeymap --- setLedTxt 200 "---"
ifKeymap --- setLedTxt 200 "--{".
ifKeymap --- setLedTxt 200 "-{-"
ifKeymap --- setLedTxt 200 "{--"

Then a “moveMouse” command with “x”: 0, “y”: -1 (up 1 pixel)

ifNotKeymap --- goTo final

Then a “delay” command with “delay”: 2000.

ifKeymap --- goTo keepalive

final:
setLedTxt 800 "[-]"
setLedTxt 200 "[\\]"
setLedTxt 200 "[|]"
setLedTxt 200 "[/]"
setLedTxt 200 "[-]"
setLedTxt 200 "[\\]"
setLedTxt 200 "[|]"
setLedTxt 200 "[/]"
setLedTxt 200 "[-]"
setLedTxt 200 "[*]"
setLedTxt 200 "|_|"

The mouse moves are so subtle that I can normally just use the mouse normally even if jiggling is on. I will still be able to click buttons etc.

@kareltucek Would be great to have mousemove commands directly in the macro language. This makes the whole macro look cleaner, and easier to export and send to someone else or post here…

3 Likes

UPDATE: Figured it out, thanks for sharing!

@maexxx love this idea. A little confused with this part of it though

is onKeymapChange a macro that needs to be set up like onInit ?

Yes, exactly. It is run when you change to that keymap.

You could, of course, also run a similar keepAlive macro within the same keymap that you normally use, but the way I wrote the macro it will automatically terminate when you switch away from the special --- keymap.

Anyway, I am glad you sorted it out. Enjoy :slight_smile:

Firstly, whoever set autoamtic lock at one minute clearly has a low understanding of security. Make security controls too painful, people will find a way, so here we all are.

I don’t understand how interleaving gui mouse movement works? I’m assuming this is pseudocode?

<gui action to move mouse one pixel right>

I meant this:

2 Likes

This is terrific. We have the same issue at work. A machine that we use for Teams conference calls will go to sleep unless we deploy someone to sit next to it just to shake the mouse periodically. I bought a mouse jiggler online fairly cheaply and it does the job.

Thanks for this but I am getting an error.

Error at jiggle start 1/3/6: Variable not found: jigglerActive)
> 3 | if ($jigglerActive) break
>   |      ^

I do see the jiggle happening however. But I keep getting an error (ERR on the LED display)

It eventually works. It seems the $jigglerActive does eventually get set, but the error keeps appearing until I resave something to the keyboard to “reset” it.

I feel like the keyboard needs to declare this variable during onInit or something before it can safely start the jiggle.

But do we really need that guard? If the user hits the key that the starts the script multiple times while the loop is active, do we risk running multiple loops if there is no guard to break early if the jiggler is active?

BTW, how do I clear the error msg on the LED display without resorting to resaving the keyboard config?

It suffices to initialize jigglerActive in your $onInit macro (setVar jigglerActive 0).

1 Like

I couldn’t get this to work. I think I could be missing something, but I think I followed what you did.
I did play around with the delay time and even increased the mouse move by 2 pixels hoping it would work in MS Teams. I also tried both with a $onInit macro and without.
Any ideas on what I could be doing wrong and why it’s not working for me?


In what manner did it not work? Did it not jiggle the mouse, or was it that Teams did not recognize the mouse jiggling as activity?

It didn’t keep my screen from timing out in my OS, or keep my teams status green for active. I have a USB mouse jiggler which does both so I was hoping I could get the macro to work similarly since I use my keyboard through a KVM switch. That way I could keep whichever computer I’m using active.

I understand that is the result, but I am still unclear about how that result was reached. The script looks good to me, having a similar one myself, but I’ll start by ruling out runtime and logic errors in the macro.

Did the keyboard report an error?
The status text would change to “ERR”, I think, if you are using a UHK 60. I’m not sure how they would be presented on the 80. Errors should show in Agent, too, if you test this with the keyboard still connected.

If you set the macro so it only moves the cursor in one direction, like only to the left, can you see the cursor move?
You can set the delay really short for this to make it easier to see. This check will tell us whether the part of the macro that moves the cursor is being triggered.

Good idea!

So I set the move pointer to 15px leftward and changed the delayUntil to 20000 and deleted my rightward move pointer, save each time and save to keyboard. And I couldn’t see the mouser pointer move at all and still didn’t keep my display awake.

Thanks for the help. This was the first macro I’ve attempted to use on this keyboard. I have the UHK 60 btw.

One thing I noticed and wasn’t sure about is that when I hover over my macro in the UHK agent, a “0” is displayed to the right. (This is the number of times this macros is used across all keymaps.)
So wasn’t sure if that has anything to do with my issue.
I’m only using one keymap and haven’t set any hotkeys for any macro. I was assuming it just ran constantly once started. I was shooting for a minute 45 seconds, just enough to keep my active in MS teams and my OS.

And I’m on the newest firmware, using a keycluster and trackball module.

Okay, so if I set the jigglerActive to a hotkey for Super + “-”, when I hit it the macro does start and work.
I guess I thought that putting “setVar jigglerActive 0” in my $onInit macro the jigglerActive macro would always run indefinitely in the loop from the time its powered on. Or maybe I was supposed to set the $onInit macro to a hotkey, idk.
From what I read it was a special macro that always run once the UHK is powered on or settings are saved to keyboard via the agent.
For now I guess I’m just going to hit the hotkey to get the macro started unless I figure out a better solution.