MACROPAD change macro keysets with keystroke

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jcalvin
 
Posts: 52
Joined: Mon Jan 04, 2016 3:37 pm

MACROPAD change macro keysets with keystroke

Post by jcalvin »

Sometimes when you're using the macropad, 12 keys isn't enough. Sometimes changing from say "browse" mode to "edit" mode requires a different set of macro key bindings. The rotary dial on the macropad supports this, but I thought it would be convenient to have a key press send key strokes (for example, switch modes) AND switch between keypad sets.

The attached version of code.py supports doing this. Two simple sample keysets (sample1.py & sample2.py) demonstrate using this optional feature.

Other changes in code.py:
- the previously posted blank the display for an empty macro set is included
- pressing a key on the keypad no longer flashes WHITE if no keystrokes will be sent and no next keypad set exists
Attachments
macropad keysets.zip
Contains code.py, sample1.py and sample2.py
(5.48 KiB) Downloaded 42 times

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: MACROPAD change macro keysets with keystroke

Post by adafruit_support_mike »

Interesting.. thanks for posting it!

User avatar
MosesMaMi
 
Posts: 8
Joined: Tue Sep 28, 2021 5:26 am

Re: MACROPAD change macro keysets with keystroke

Post by MosesMaMi »

First of all, I am new to this forum.
I was able to obtain a macropad and am using it on Windows 10.

@jcalvin Thank you for the interesting modification. I was looking for something exactly like that.

Unfortunately, I have a problem with your code: If I do not want to send some "pure" keystroke(s), but some kind of macro, the code crashes.

E.g., my idea was to open Zoom using a "desktop" macro-set and after opening Zoom, switch to the according keyset.
Opening Zoom works reliably using this line of code:
(I have a German keyboard layout, where Z and Y are switched, so I need to search for "Yoom".)

Code: Select all

(0x100000, 'ZOOM', [Keycode.GUI, -Keycode.GUI, 0.1, 'Yoom', 0.1, Keycode.ENTER]), # open Zoom
Together, with your modified code.py, I used this line:

Code: Select all

(0x303000, 'Zoom', [Keycode.GUI, -Keycode.GUI, 0.1, 'Yoom', Keycode.ENTER], 'Win Zoom'), # open Zoom
Unfortunately, this results in the macropad displaying "code done running" and the computer behaving strangely. It looks like, as if the GUI-key is still considered "pressed", although the start-menu is not showing.

Checking your modifications, I noticed that you made a change to the line that should actually releases the key (negative integer): It was changed from

Code: Select all

macropad.keyboard.release(-item)
to

Code: Select all

MACROPAD.keyboard.release(item)
Furthermore, you removed the processing of float number values which makes the macro wait for a described amount of time (lines 150 and 151 in the original code.py):

Code: Select all

elif isinstance(item, float):
    time.sleep(item)
Does anybody have an idea, why the macropad hangs after my "macro" keypresses?
I tried to incorporate the "missing" lines into @jcalvin's modification, but the macropad still only shows "Code done running".

Best
MosesMaMi

User avatar
jcalvin
 
Posts: 52
Joined: Mon Jan 04, 2016 3:37 pm

Re: MACROPAD change macro keysets with keystroke

Post by jcalvin »

Interesting - we seem to be working from different base code.
The code you changed attributing to my changes weren't my changes. Those lines were as they appeared in the base code I started from - well, the elif isinstance(item, float) code wasn't even there.

To make things more interesting, the original author, or someone, has made a large set of edits to the code posted on Adafruit in the current learn guide. In particular they've changed many variable names from all UPPER CASE to all lower case - like "MACROPAD" became "macropad". This may have made the code match some style guide, but it certainly makes it difficult to do comparisons and find edits that change the behavior of the code.

I suspect that the ability to handle the delays (the 0.1 in your macro description) simply wasn't handled in the code I started from. I suspect this because "import time" was added at some point after I branched off on my version. My guess is that the "time.sleep(item)" is causing the code to terminate. Without the "import time" the sleep line would fail.

As a quick try to fix it, you could try adding "import time" with the other import statements. But it may not be enough...

It will take a bit of time to figure out what's going on between the edits made by the good folk at Adafruit and the changes I made based on an earlier version.

User avatar
jcalvin
 
Posts: 52
Joined: Mon Jan 04, 2016 3:37 pm

Re: MACROPAD change macro keysets with keystroke

Post by jcalvin »

I've quickly moved my code into the latest from Adafruit. At first blush it works, but I haven't tried it for any of the additional functionality that Adafruit added (delays, tones, ?)

The updated code is attached. Let me know if it works for you.
Attachments
code.py
(9.3 KiB) Downloaded 37 times

User avatar
MosesMaMi
 
Posts: 8
Joined: Tue Sep 28, 2021 5:26 am

Re: MACROPAD change macro keysets with keystroke

Post by MosesMaMi »

Thank you very much @jcalvin!

Adding the import time line already worked for me, at least in the version I already modified from you.

Your second code.py seems to work as well (I am not using tones or such).

Now, my keypress-macro successfully opens Zoom and switches to the according macro-set.

Locked
Please be positive and constructive with your questions and comments.

Return to “AdaBox! Show us what you made!”