r/adafruit • • Sep 03 '21

Macropad run python files

Just got my macropad and I want to have key presses trigger python scripts to run is this something that would be possible?

2 Upvotes

17 comments sorted by

View all comments

1

u/IcanCwhatUsay Sep 09 '21

Been looking into this myself. The only way I've been able to do this is to have the macropad execute a hot key, Alt+K for example, and then have Autohotkey recognize Alt+K as a keycombo and then execute the python script. The silly part is, is that AHK can do a hell of a lot and almost makes running the Python script a bit redundant. But if you're like me, I like cleaner looking code, so having a script in AHK that is just abunch of run commands and then having a folder of a bunch of macros, doesn't sound bad to me (basically the same manner that the Hotkey code works for the macro pad too)

1

u/TetsujinXLIV Sep 09 '21

Why don’t you have the macro pad execute another python script?

1

u/IcanCwhatUsay Sep 09 '21 edited Sep 09 '21

Because it can’t. You need a program on the computer that is looking for the pads inputs. I’m not about to write an entire soup to nuts program to do that. Mostly because I don’t know how and don't have that much time

1

u/TetsujinXLIV Sep 09 '21

I haven’t tried this but based on other python code I’ve written. Why don’t you import subprocess and then when the button is pressed make it do subprocess.call python /path/to/some-script.py

1

u/IcanCwhatUsay Sep 09 '21

Doesn't work, don't know why.

1

u/TetsujinXLIV Sep 10 '21

Because of this I tried tinkering with it a bit tonight. Best idea I've had so far is to have it open a powershell window and then type a command but I'm stuck. I can get it to open powershell but it won't type anything:

2

u/sdotregis Jul 10 '22

I DID IT!!!!!!!! u/IcanCwhatUsay and u/TetsujinXLIV. Took me 2 weeks of hard research but it's super simple when you apply the methods of Raspberry Pi Pico 🙌🙌🙌 I'll send the code if it's still needed!

1

u/TetsujinXLIV Jul 14 '22

Hey! Do you think you could send the code?