Results 1 to 3 of 3

Thread: Activism for beginners, or, how to use keyboard macros

  1. #1

    Activism for beginners, or, how to use keyboard macros

    Hi all,

    most of you will be aware of the current CG. One of the results of CGs is that it brings a lot of players together in one system. And like everywhere else, where you have waterholes, you have predators.
    Some of these predators may be there just "for te lulz". Ignore them - in every aspect of this word, including the "Block Player" button on the comms panel (which will not only block them from comms, but also reduce the likelihood of them instancing with you):



    For everyone else, though, there's the continuing problem of communications. The comms panel (top left) is there, and it's useful, but if you are an aspiring environmental activist, opening the panel, typing your message, closing the panel and returning to flying your spaceship may mean that you've already crashed into the asteroid you wanted to protect from being strip-mined.
    Not exactly what you might have had in mind.

    This is why most people use some sort of scripting tool. One of them, which is very popular in ED, is Voice Attack. I've never (yet) tried it myself, but besides the obvious of permitting voice control to trigger specific actions, it also (reputedly) allows to script actions on the press of a key - on your keyboard, joystick or wherever.
    Instead, what I use is AutoHotKey. This is a free scripting tool that can take keyboard input (so no voice control here) and perform multiple actions on your PC on the press of a single key. Since I usually use a tenkeyless keyboard for my day-to-day computer stuff, I added a nice mechanical numeric block to my setup as input towards AHK. Easier to hit the correct key when wearing a VR headset, and more robust, too.

    I started off with two keys:
    - the big fat "0" key triggers a screenshot
    - the similarly big and fat "enter" key switches my microphone for those rare cases when I use discord

    Since I am somewhat miffed at the thought of Manatees being shipped off in a Megaship just to be killed in a remote system to provide "gourmet" food to the people there (wanna guess how much of that ends up with the general populace?), I added a few more commands to my numpad. This took a little fumbling and trial-and-error, as sending commands to ED's comms panel apparently isn't that straightforward. I won't go into the actual installation and setup of AHK here (it's really straightforward: download, install, create (or use one of the examples) a text file for your ahk script, double click on it and it's lurking in the background), but rather just want to provide an example of what is working on my PC (and, incidentally, put a backup copy of the script on FD's servers ) as well as giving you activists, pirates and freedom fighters out there a (simple) means of communicating your demands and intentions. Intercepting someone jsut because you can is dull and boring. Add a little communication to that, and it has at least a chance of evolving into gameplay.

    And this is my current script. I'll seperate it into blocks so I can add a little more drivel after each segment:

    Code:
    #SingleInstance force
    #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
    ; #Warn  ; Enable warnings to assist with detecting common errors.
    SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
    SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
    
    SetNumLockState, AlwaysOn
    The header. Most of the stuff here I just copied form one of the example scripts, so I actually have very little idea of what is going on here. Especially that numlock always on doesn't seem to work as I would expect it to, which is why, in the following, I'm using both possible events from each physical key to trigger the same action. Remeber, I'm usually wearing a VR headset, so I'm not really inclined to peer around the edges to check whether the NumLock LED is actually lit up (and, in fact, it's hard to see even without the goggles, as it sits hidden between the keys).

    Code:
    Numpad0::
    NumpadIns::
    ;    Send, Numpad 0
        Send {F10 down}            ; send F10 to trigger ED's screenshot 
        Sleep 25                ; Thanks to CMDR Zhao and Alec Turner
        Send {F10 up}
    Return
    Anyone who has ever written any kind of program will recognize this structure. It starts with a condition, in this case "Numpad0::" or "NumpadIns::". The same physical key, but depending on the state of the NumLock, it may trigger two different events.
    The next line starts with a semicolon - this indicates that everything else on this line (after the semicolon) is a commentary and not evaluated by AHK. If I were to remove the semicolon, AHK would just send out the "Numpad 0" event - acting like it wasn't even there, eavesdropping on whatever is happening on the keyboard.
    After that, we have three lines where AHK is actually doing something:
    Send {F10 down} sends the event for the F10 key being pressed
    Sleep 25 waits for 25 milliseconds and
    Send {F10 up} sends the event for the F10 key being released.
    This is one of the peculiarities of the combination of AHK with ED. ED apparently checks for both key pressed and key released events, at least in some cases, and requires some delay inbetween. Nothing to especially worry about, but you have to keep it in mind - Send {F10} simply doesn't work with ED.
    The Return command at the end of the block closes the block, AHK may now exit the script without having to go through all the remaining conditions.

    Code:
    ; 2 to open the comms panel
    ; 0 to go back
    ; /t for target
    ; /l for local
    Just some commentary so I don't forget what I did in six month's time. This is also something you have to set up in ED - I usually use my HOTAS, but I've set up the key "2" as a secondary key to open the comms panel, and the key "0" as a secondary "back" key for the UI. Whatever kind of input method you use for the comms panel, you'll have to replace your stuff further below wherever I used "2" and "0".
    /t and /l are the two comms panel commands for target(ed ship) and local comms. There are a few more, accessible through typing /help in the comms window.

    Code:
    Numpad1::
    NumpadEnd::
    ;    Send, Numpad 1
        Send {2    down}            ; open comms panel
        Sleep 25
        Send {2 up}
        Sleep 25
        Send /l                ; send on the local channel
        Sleep 50
        Send {Enter down}
        Sleep 50
        Send {Enter up}
        Sleep 50
        Clipboard = This system is under embargo 
        Sleep 50
        Send ^v
        Sleep 50
        Send {space}
        Sleep 50
        Clipboard = by the Manatee Liberation Front. 
        Sleep 50
        Send ^v
        Sleep 50
        Send {space}
        Sleep 50
        Send {Enter down}
        Sleep 50
        Send {Enter up}
        Sleep 50
        Clipboard = Please leave immediately and in peace. 
        Sleep 50
        Send ^v
        Sleep 50
        Send {space}
        Sleep 50
        Send {Enter down}
        Sleep 50
        Send {Enter up}
        Sleep 50
        Clipboard = Save the Manatees!
        Sleep 50
        Send ^v
        Sleep 50
        Send {Enter down}
        Sleep 50
        Send {Enter up}
        Sleep 50
        
        Send {Esc down}                    
        Sleep 50
        Send {Esc up}                    
        Sleep 250
        Send {0    down}        ; close the comms panel    
        Sleep 50
        Send {0 up}
        Sleep 50
    Return
    Ok, this is a pretty mouthfull. But very simple, so no need to be afraid.
    What it actually does:
    - check for Numpad 1/Numpad End key pressed
    - opens the comms panel
    - sends /l to transmit on the local channel
    - assigns some text to the clipboard, then copies the clipboard to the comms panel and sends it via "Enter"
    - repeat twice
    - exit from the entry window, then closes the comms panel through sending "0"
    All that "up", "Sleep" and "down" stuff is just there to get ED to swallow it. Leave it out, and ED will either ignore the "Enter" key commands, or swallow some arbitrary characters. Took me the better part of two hours to find out what works and what doesn't - which is another reason for posting this here. I just have the hope that, if more people knew how to do this, I'd get less uncommunicative interdictions and perhaps a bit more player interaction.

    Code:
    Numpad2::
    NumpadDown::
    ;    Send, Numpad 2
        Send {2    down}            ; open comms panel
        Sleep 25
        Send {2 up}
        Sleep 25
        Send /t                ; send to the target
        Sleep 50
        Send {Enter down}
        Sleep 50
        Send {Enter up}
        Sleep 50
        Clipboard = You were asked to leave. 
        Sleep 50
        Send ^v
        Sleep 50
        Send {space}
        Sleep 50
        Send {Enter down}
        Sleep 50
        Send {Enter up}
        Sleep 50
        Clipboard = I am asking again. 
        Sleep 50
        Send ^v
        Sleep 50
        Send {space}
        Sleep 50
        Send {Enter down}
        Sleep 50
        Send {Enter up}
        Sleep 50
        Clipboard = LEAVE. THIS. SYSTEM. NOW.
        Sleep 50
        Send ^v
        Sleep 50
        Send {Enter down}
        Sleep 50
        Send {Enter up}
        Sleep 50
        
        Send {Esc down}                    
        Sleep 50
        Send {Esc up}                    
        Sleep 250
        Send {0    down}        ; close the comms panel    
        Sleep 50
        Send {0 up}
        Sleep 50
    Return
    Same stuff for the Numpad 2 key. This time, I'm sending on the target channel (I assume that by now I have targeted a perpetrator), and of course I am increasing the pressure.

    Code:
    Numpad3::
    NumpadPgDn::
    ;    Send, Numpad 3
        Send {2    down}            ; open comms panel
        Sleep 25
        Send {2 up}
        Sleep 25
        Send /t                ; send to the target
        Sleep 50
        Send {Enter down}
        Sleep 50
        Send {Enter up}
        Sleep 50
        Clipboard = This is nothing personal, but we WILL save the Manatees. 
        Sleep 50
        Send ^v
        Sleep 50
        Send {space}
        Sleep 50
        Send {Enter down}
        Sleep 50
        Send {Enter up}
        Sleep 50
        
        Send {Esc down}                    
        Sleep 50
        Send {Esc up}                    
        Sleep 250
        Send {0    down}        ; close the comms panel    
        Sleep 50
        Send {0 up}
        Sleep 50
    Return
    And again for the Numpad 3 key. Again a shorter message - by now, I have deployed hardpoints, and with all those (necessary) delays (Sleep) in the script, those first two scripts will take up a considerable time - time I can't spend when I'm attacking a Cutter with my Sidewinder.
    And yes, the 250 ms after the ESC to get out of the comms entry window are apparently necessary. I tried it with 50 or 100 ms, and it didn't work. Looks like ED is doing a bit of cleanup when you leave the entry window and just needs some time.

    Code:
    Numpad4::
    NumpadLeft::
    ;    Send, Numpad 4
    Return
    
    Numpad5::
    NumpadClear::
    ;    Send, Numpad 5
    Return
    
    Numpad6::
    NumpadRight::
    ;    Send, Numpad 6
    Return
    
    Numpad7::
    NumpadHome::
    ;    Send, Numpad 7
    Return
    
    Numpad8::
    NumpadUp::
    ;    Send, Numpad 8
    Return
    
    Numpad9::
    NumpadPgUp::
    ;    Send, Numpad 9
    Return
    
    NumpadDot::
    NumpadDel::
    ;    Send, Numpad Dot
    Return
    
    NumLock::
    ;    Send, Num Lock
    Return
    
    NumpadDiv::
    ;    Send, Numpad Div
    Return
    
    NumpadMult::
    ;    Send, Numpad Mult
    Return
    
    NumpadAdd::
    ;    Send, Numpad Add
    Return
    
    NumpadSub::
    ;    Send, Numpad Sub
    Return
    Placeholders for most of the remainder of my numpad keys. Enough space to add a few more prearranged messages. With a Sidey, I won't need any warnings for a wide load coming through the slot, but I might add some messages for when I'm interdicted - or when I'm running.

    Code:
    NumpadEnter::
    ;    Send, NumpadEnter
        Send {alt down}
        Send {ctrl down}
        Send {NumpadEnter down}            
        Sleep 10                
        Send {NumpadEnter up}
        Send {ctrl up}
        Send {alt up}
    Return
    And finally, the Numpad "Enter" key. That one simply sends out an Alt-Ctrl-Enter combo, which in turn I have set up in Discord as microphone PTT key. So, AHK isn't restricted to sending events to any specific appplication - on the contrary. It just listens to anything coming from the keyboard(s) and, if something it is sensitive to comes up, replaces that with its own set of commands. Or whatever - AHK can do much more than this. It has the usual syntax for loops or conditions - just check the link to the site I've given above, if you want to see more.

    Hoping to hear from you in game .

  2. #2
    Great work there...

    Two things. Firstly and I don't know the answer here, but is this permitted by FD?

    Secondly. Manatee Liberation Front. Initialised, that's one "I" away from being a description of Stiffler's mum.

  3. #3
    Firstly, yes - or at least tolerated. Pirates have been using this since 2015, and this is (essentially) the same mechanism VoiceAttack uses to control your ship. What would not be allowed (and what makes some of the more advanced macros so difficult) is to get real time data from the game (like the current cursor position in the menus) and use that to control the game.

    Secondly - well, there aren't that many unique and (for western brains) understandable initializations around any more. Check out e.g. https://www.abbreviations.com/