0

MACROPAD change macro keysets with keystroke
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MACROPAD change macro keysets with keystroke

by jcalvin on Wed Sep 15, 2021 1:57 pm

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 3 times

jcalvin
 
Posts: 46
Joined: Mon Jan 04, 2016 3:37 pm

Re: MACROPAD change macro keysets with keystroke

by adafruit_support_mike on Sun Sep 19, 2021 10:44 pm

Interesting.. thanks for posting it!

adafruit_support_mike
 
Posts: 63716
Joined: Thu Feb 11, 2010 2:51 pm

Re: MACROPAD change macro keysets with keystroke

by MosesMaMi on Tue Sep 28, 2021 6:02 am

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 | TOGGLE FULL SIZE
(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 | TOGGLE FULL SIZE
(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 | TOGGLE FULL SIZE
macropad.keyboard.release(-item)
to
Code: Select all | TOGGLE FULL SIZE
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 | TOGGLE FULL SIZE
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

MosesMaMi
 
Posts: 2
Joined: Tue Sep 28, 2021 5:26 am

Re: MACROPAD change macro keysets with keystroke

by jcalvin on Tue Sep 28, 2021 7:50 am

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.

jcalvin
 
Posts: 46
Joined: Mon Jan 04, 2016 3:37 pm

Re: MACROPAD change macro keysets with keystroke

by jcalvin on Tue Sep 28, 2021 8:31 am

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 1 time

jcalvin
 
Posts: 46
Joined: Mon Jan 04, 2016 3:37 pm

Re: MACROPAD change macro keysets with keystroke

by MosesMaMi on Tue Sep 28, 2021 10:47 am

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.

MosesMaMi
 
Posts: 2
Joined: Tue Sep 28, 2021 5:26 am

Please be positive and constructive with your questions and comments.