zettelkasten/OneNoteExport/Schnelle_Notizen/Sammel_Infos/42_AutoHotkey.md
Ralf Koop 5a108aa2b4 .
2023-08-25 23:29:11 +02:00

3.0 KiB

AutoHotkey

Montag, 16. März 2020

13:21

 

Scripting may be scary to some of you, but AutoHotkey isn't really all that bad, and we're going to show you how to write some basic scripts. Here are the identifiers for our three functions:

  • Single-click is #F20

  • Double-click is #F19

  • Click and hold is #F18

Warning: There is also a side button on the new Surface Pen, which, by default is set to right-click. The identifier for right-click is rbutton. This is a tricky function to reprogram as once you've changed right-click using a script, it affects right-click functionality across the entire system. Best to steer clear.

Before we do anything, we will need to decide which function we wish to modify. So, for example, let's start with our single-click eraser function. For single-click, we start like this:

  • #F20::

Everything to the left of the "::" defines the function we are using, so, in this case, a single-click of the eraser. We then start a command string. As an example, let's look how we would script an undo (Ctrl + Z) function.

  • #F20 :: ^z

  • return

So, in this example, control is represented by the symbol "^", and, in conjunction with "z", it gives us the undo command. Return ends the command string. Pretty neat right?

Let's look at another example, where we'll script single-click to copy and double-click to paste.

  • #F20 :: ^c

  • sleep 300

  • #F19 :: ^v

  • return

Following the same basic format, we first define our single-click as Control + C. Sleep is a command to add time (in milliseconds) before the next function can operate. We use 300 ms to give the system ample time to copy the selection to the system's clipboard.

You can also program the eraser to launch applications as long as you know the name of the executable. However, this is already a feature that Microsoft gives in their Surface app, so you could easily use that as well. Just for learning purposes, let's see how it works in AutoHotkey.

  • #F20 :: Run photoshop

  • return

This simple command line will allow Adobe Photoshop to open with a single click from your Surface Pen's eraser. Being able to launch a program in this fashion only works with certain applications. This means that with most applications you will need to run the entire path (e.g. Run, %A_ProgramFiles%\Some_Program\Program.exe).

To open a website, the script would look like this:

This will program a single-click from your Surface Pen eraser to open the specific link in your default browser. Needless to say, these examples are rudimentary, and, really, the possibilities of how you can program your Surface Pen's eraser are endless; these examples are just to get you going. For more elaborate scripting, visit the AutoHotkey forums.

 

Aus <https://windows.gadgethacks.com/how-to/reprogram-your-surface-pen-buttons-do-anything-you-want-0166903/>