Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using macros from script in R13+ (sample code) #261

Open
muchimi opened this issue Nov 12, 2019 · 1 comment
Open

Using macros from script in R13+ (sample code) #261

muchimi opened this issue Nov 12, 2019 · 1 comment
Labels
documentation Changes to the documentation.

Comments

@muchimi
Copy link

muchimi commented Nov 12, 2019

Since the documentation and sample code on writing macros and running them from a plugin goes back to R7 (I think) and doesn't work with R13 - here's working code that does in the current version.

Figured I'd share since it took me a few hours to figure this out.

import gremlin
from gremlin.input_devices import keyboard, macro
from configuration import * # load constants from the configuration.py file in the same folder as the plugin - defining the devices connected to this PC
# example (for my TM throttle device):
# TM_THROTTLE_ID = 7
# TM_THROTTLE_HWID = 72287236
# TM_THROTTLE_NAME = "Throttle - HOTAS Warthog"
# TM_THROTTLE_GUID = "{A60B8530-25E9-11E7-8003-444553540000}"
# 
# script mode:
# MODE_ALL = "Default"

# define devices
tmthrottle = gremlin.input_devices.JoystickDecorator( TM_THROTTLE_NAME, TM_THROTTLE_GUID, MODE_ALL )

# define macro
toggle_light_macro = macro.Macro()
toggle_light_macro.tap("L")

# other functions are press() release() pause(seconds_as_floating_point) - add them in sequence they need to be executed so
# issue a control-A, hold it for half a second
# m.press("leftcontrol")
# m.press("A")
# m.pause(0.5)
# m.release("A")
# m.release("leftcontrol")
# special keys are: 
#    "f1"    "f2"    "f3"    "f4"    "f5"    "f6"    "f7"    "f8"    "f9"    "f10"    "f11"    "f12"
#    "printscreen"    "scrolllock"    "pause"    "insert"    "home"    "pageup"    "delete"    "end"    "pagedown"    "up"    "left"    "down"    "right"
#    "numlock"    "npdivide"    "npmultiply"    "npminus"    "npplus"    "npenter"    "npdelete"
#    "np0"    "np1"    "np2"    "np3"    "np4"    "np5"    "np6"    "np7"    "np8"    "np9"
#    "backspace"    "space"    "tab"    "capslock"
#    "leftshift"    "leftcontrol"    "leftwin"    "leftalt"    "rightshift"    "rightshift2"    "rightcontrol"    "rightwin"    "rightalt"
#    "apps"    "enter"    "esc"


# toggle lights on press or release
@tmthrottle.button(24)
def toggle_lights(event, joy, vjoy):
	gremlin.macro.MacroManager().queue_macro(toggle_light_macro)  # runs the macro


@WhiteMagic WhiteMagic added the documentation Changes to the documentation. label Nov 16, 2019
@WhiteMagic
Copy link
Owner

Yeah, a bunch of the documentation needs updating :-) I hopefully get around to revising that at some point. I also did some work on making automatic code documentation via Sphinx but that still as some issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Changes to the documentation.
Projects
None yet
Development

No branches or pull requests

2 participants