An extended version of the hotkeys demo code using action classes

Overview

An extended version of the hotkeys application using action classes.

In adafruit's Hotkeys code, a macro is using a series of integers, assumed to be Keycodes. While it's great to make it simple and minimal, it doesn't allow for other types of actions, and mixing them. Consumer Controls for example are also encoded as integers.

Macros With Action Classes

Action classes let you encapsulate actions with a class instance, serving as markups in the code. I tend to prefer short names, but more explicit longer names are available. A macro can be a single item or a list (that reduces the number of parenthesis when there's only one).

Shortcuts and Keycodes

Press or release one or more keys with a keycode name as strings. It presses the key and only releases it at the end of the macro, unless you specify to release in two ways: a negative shortcut, or 0. Keycodes can also be represented with the Keycode.THING int. If the key code is not found, it defaults to layout.keycodes().

# long version, with key names
    (0x004000, 'Redo', [ Shortcut("COMMAND", "SHIFT", "Z") ]),
# short version:
    (0x004000, 'Undo', [ S("COMMAND", "Z") ]),
# importing Keycode
    (0x004000, 'Undo Win', [ Shortcut(Keycode.CONTROL, Keycode.Z) ]),
# releasing all (prefered)
    (0x004000, 'Things', [ S("ALT", "A"), 0, S("ALT", "B") ]),
# releasing one (holding ALT)
    (0x004000, 'Other', [ S("ALT", "A"), -S("A"), S("B") ]),

Type a string

# long version
    (0x004000, 'Hello', [ Type("Hello world") ]),
# short version
    (0x004000, 'Taco', [ T(" :taco:") ]),

Consumer Control keys

The consumer_control_extended module can be found in the Layout Repository and contains a bunch of names for consumer control functions, basically dumped from the USB HID specifications. Some might even do something !

# as strings
    (0x202000, 'Volume-', Control("VOLUME_DECREMENT")),
    (0x202000, 'Volume+', Control("VOLUME_INCREMENT")),
# as int (start calculator)
    (0x202000, 'Calc', Control(0x192)),
# with ConsumerControlExtended
from consumer_control_extended.ConsumerControlExtended import *
...
    (0x202000, 'Calc', Control(AL_CALCULATOR)),

Mouse

Note that mouse movements are relative, and depend on the computer's setup. They are only done once on press and not repeated in this implementation. Mouse buttons are held until the macro key is released.

# click 1 = left, 2 = right, 3 = middle
    (0x202000, 'Click', Mouse(1)),
# mouse move
    (0x202000, 'Zipzap', Mouse(x=100, y=100)),
# mouse wheel
    (0x202000, 'Wheel+', Mouse(wheel=10)),

Midi notes

# midi notes as strings, with or without velocity (127 by default)
    (0x004000, 'Hello', [ Midi( "A-1#", ("C1", 64) ) ]),
# midi notes as numbers
    (0x004000, 'Taco', [ M( 10 ), M( (11, 100) ) ]),

Play tones

# arpeggio
    (0x202000, 'Arpeggio',
        Tone(
            ("C6", 0.2), ("E6", 0.2), ("G6", 0.2), ("C7", 0.2),
            ("G6", 0.2), ("E6", 0.2), ("C6", 0.5),
        )
    ),

Custom function calls

Instead of an action, you can put a function, expecting 3 parameters, the Macropad Instance, the number of the key being pressed, the index of the action in the current macro's list.

# turn off the lights when pressing the encoder, and hide the interface

def onoff(pad, key, idx):
    # pad.display.brightness = 0
    pad.group.hidden = not pad.group.hidden
    pad.display.refresh()
    if pad.group.hidden:
        pad.pixels.fill(0)
        pad.pixels.show()

app = {
    ...
    'macros' : [
    ...
        # Encoder button ---
        (0x000000, '', onoff)
    ]
}

Enter and leave

You can specify a function to be called when switching apps (macro pages), one when you enter, one when you leave. They take the MacroPad instance, the previous app and the current app (instances of App).

# beep when we start this page
# restore the lights and screen when we leave it
# or we won't know where we are when switching pages

beep = Tone(("C6", 0.08), 0.05, ("E6", 0.10))

def entering(pad, prev_app, next_app):
    beep.action()

def leaving(pad, prev_app, next_app):
    pad.group.hidden = False
    pad.display.refresh()

app = {
    'name' : 'Test Macros', # Application name
    'enter' : entering,
    'leave' : leaving,
    'macros' : [
    # ...
    ]
}

Mixing

# type a blod string in some text editor, possibly, and beep
    (0x004000, 'Bold String',
        [
            Shortcut("CONTROL", "B"), # shortcut
            0,                        # release
            Type("Is this bold ?",    # type
            0.5,                      # wait
            Tone( ("C6", 0.08) ),     # beep
        ]
    ),

International keyboards support

The keyboard layout and keycode can be configured in the macros_config.py file, with modules from the Layout Repository.

from keyboard_layout_mac_fr import KeyboardLayout
default_layout = KeyboardLayout
from keycode_mac_fr import Keycode
default_keycode = Keycode
Owner
Neradoc
Neradoc
Viewer for NFO files

NFO Viewer NFO Viewer is a simple viewer for NFO files, which are "ASCII" art in the CP437 codepage. The advantages of using NFO Viewer instead of a t

Osmo Salomaa 114 Dec 29, 2022
Easytile blender - Simple Blender 2.83 addon for tiling meshes easily

easytile_blender Dead simple, barebones Blender (2.83) addon for placing meshes as tiles. Installation In Blender, go to Edit Preferences Add-ons

Sam Gibson 6 Jul 19, 2022
A Regex based linter tool that works for any language and works exclusively with custom linting rules.

renag Documentation Available Here Short for Regex (re) Nag (like "one who complains"). Now also PEGs (Parsing Expression Grammars) compatible with py

Ryan Peach 12 Oct 20, 2022
A module to develop and apply old-style links

Old-Linkage-Dev (OLD) Old Linkage Development is a module to develop and apply old-style links. Old-style links stand for some traditional or conventi

Tarcadia 2 Dec 04, 2021
BlackMamba is a multi client C2/post exploitation framework

BlackMamba is a multi client C2/post exploitation framework with some spyware features. Powered by Python 3.8.6 and QT Framework.

Gustavo 873 Dec 29, 2022
Our Ping Pong Project of numerical analysis, 2nd year IC B2 INSA Toulouse

Ping Pong Project The objective of this project was to determine the moment of impact of the ball with the ground. To do this, we used different model

0 Jan 02, 2022
A comprensive software collection for nmea manipulation

nmeatoolkit A comprensive software collection for nmea manipulation; it includes a library and a collections of command line tools. Library pipes: con

Davide Gessa 1 Sep 14, 2022
Recreating my first CRUD in python, but now more professional

Recreating my first CRUD in python, but now more professional

Ricardo Deo Sipione Augusto 2 Nov 27, 2021
ASVspoof 2021 Baseline Systems

ASVspoof 2021 Baseline Systems Baseline systems are grouped by task: Speech Deepfake (DF) Logical Access (LA) Physical Access (PA) Please find more de

91 Dec 28, 2022
Blender addon - Breakdown in object mode

Breakdowner Breakdown in object mode Download latest Demo Youtube Description Same breakdown shortcut as in armature mode in object mode Currently onl

Samuel Bernou 4 Mar 30, 2022
Small scripts to learn about GNOME internals

gnome-hacks This is a collection of APIs that allow programmatic manipulation of the GNOME shell. If you use GNOME (the default graphical shell in Ubu

Alex Nichol 5 Oct 22, 2021
Covid-ml-predictors - COVID predictions using AI.

COVID Predictions This repo contains ML models to be trained on COVID-19 data from the UK, sourced off of Kaggle here. This uses many different ML mod

1 Jan 09, 2022
A repository containing useful resources needed to complete the SUSE Scholarship Challenge #UdacitySUSEScholars #poweredbySUSE

SUSE-udacity-cloud-native-scholarship A repository containing useful resources needed to complete the SUSE Scholarship Challenge #UdacitySUSEScholars

Nandini Proothi 11 Dec 02, 2021
MinimalGearDisplay, Assetto Corsa app

MinimalGearDisplay MinimalGearDisplay, Assetto Corsa app. Just displays the current gear you are on. Download and Install To use this app, clone or do

1 Jan 10, 2022
Check is a integer is even

Is Even Check if interger is even using isevenapi. https://isevenapi.xyz/ Main features: cache memoization api retry handler hide ads Install pip inst

Rosiney Gomes Pereira 45 Dec 19, 2022
HPomb Is Socail Engineering Tool , Used For Bombing , Spoofing and Anonymity Available For Linux And Android(Termux)

HPomb v2020.02 Coming Soon Created By Secanonm HPomb Is Socail Engineering Tool , Used For Bombing , Spoofing and Anonymity Available For Linux And An

Secanonm 10 Jul 25, 2022
Read and write life sciences file formats

Python-bioformats is a Python wrapper for Bio-Formats, a standalone Java library for reading and writing life sciences image file formats. Bio-Formats

CellProfiler 106 Dec 19, 2022
Multiperiod Reports by Month/Quarter/Year in Beancount.

Multiperiod Reports by Month/Quarter/Year in Beancount. Plotting income and expenses over time. Treemap plot of expenses.

Altynbek Isabekov 16 Aug 13, 2022
The worst and slowest programming language you have ever seen

VenumLang this is a complete joke EXAMPLE: fizzbuzz in venumlang x = 0

Venum 7 Mar 12, 2022
A python program, imitating functionalities of a banking system

A python program, imitating functionalities of a banking system, in order for users to perform certain operations in a bank.

Moyosore Weke 1 Nov 26, 2021