Translates surface pen button clicks to input readable by Python.
-
Download the pinput1, 2, and 3
.pyw
files from/Input-Files
-
Make each file a shortcut
- Open "File Explorer"
- Go to the folder where you downloaded the "pinput" (pen input) files
- Right click on one of the files
- Click "Create shortcut"
- Do that for the other two pinput files
-
Open "Settings > Devices > Pen and Windows Ink", and scroll down to "Pen Shortcuts"
-
For each option (Click once, Double click, Press and hold), do the following:
- Choose the option "Launch a classic app"
- Click "Browse"
- Navigate to the folder with the pinput shortcut files
- Select the respective input file for each click method
-
You're all set up! Write a script to process inputs, or use one from /Examples.
Now you have inputs, but how do you actually use them? Here is a basic example of how to read input from the pen.
import zmq
import time
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")
while True:
message = socket.recv()
print("[RECEIVED] %s" % message)
time.sleep(0.1)
if message == b'input1':
print("Single-click recieved!")
if message == b'input2':
print("Double-click recieved!")
if message == b'input3':
print("Hold-click recieved!")
socket.send(b"World")
WOAH, THAT'S COOL! But what does it do? Lets break this script down:
-
import zmq
andimport time
-zmq
is required to send messages between scripts (if not already installed, runpip install zmq
), andtime
is required for a short delay in the main loop. -
context = zmq.Context()
tosocket.bind("tcp://*:5555")
- Starts listing for input on port 5555 from the pinput scripts. -
while True:
andtime.sleep(0.1)
- This is the main loop that checks for input. It doesn't work without a short delay. Don't ask me, I don't know why. I copied some of this code from stackoverflow. -
message = socket.recv()
- Reads messages sent on port 5555 (pen inputs) -
The
if
statements - Checks for inputs sent, you can customize these to fit your needs. Replace theprint
statements with whatever you need. -
socket.send(b"World")
- Sends "World" back to the input scripts so they know the input was recieved.
There are example input processors in the /Examples folder.
If you have any problems, you can submit an Isuse under the issues tab.