Need Help with Surface Pen (4 functions for 1 Button, including Toggles)

Get help with using AutoHotkey and its commands and hotkeys
Phazor
Posts: 10
Joined: 28 Jul 2019, 18:15

Need Help with Surface Pen (4 functions for 1 Button, including Toggles)

Post by Phazor » 28 Jul 2019, 20:52

Can someone help me and tell me what's wrong with this code, and possibly fill in the gaps for the other things I'm trying to do? I don't know how to remap the Surface Pen (especially the right click button) so I'm using another software to remap the buttons to Hover Right Click and Middle Mouse Click. I want to add 3 (or 4) functions to both the right click and the middle click and multiple functions to clicking both together, and make a simple full screen transparent GU Ithat allows me to type by writing, convert it into text, and send the text out, either into the "air" (no text field, to use written text as hotkeys for software that has no text field), or into a text field.

This is how I would like the Surface Pen to behave

*Single Right Click* = Right Click
*Double Right Click* = Alt Toggle
*Hold Right Click* = "Send ("")" … (I have another software that controls hold right click)
*Double Right Click AND HOLD* = Toggle Handwriting Recognition typing (Not Microsoft's input panel/box, but a full screen transparent overlay that allows a user to write anywhere on the screen and send text out) I was hoping someone knew how to design this with AHK GUI using InkEdit.

*Single Middle Click* = Ctrl Toggle
*Double Middle Click* = Shift Toggle
*Hold Middle Click* = Middle Click (Hold until release)
*Double Middle Click AND HOLD* = Middle Mouse Click + Ctrl (Hold until release)

I also want to add "Double Middle Click AND HOLD" function if possible, but I don't know how to do that...

*Single Right and Middle Click* = Snippet Tool/Screenshot
*Double Click* = ???
*Hold* = ???
*Double Click AND HOLD* = ??? (whatever is useful)


THE PROBLEM with the code I do have, and a Recap:

1. The Middle Mouse Single Click Ctrl Toggle appears to be interrupting the Hold Middle Mouse function. When I hold Middle Mouse, the Ctrl toggle activates but I only want Ctrl toggle to activate when I tap, not hold, the middle click/eraser button.

2. I prefer to use AHK to remap the pen's buttons, not a different software, but if that's not possible, that's ok.

3. Looking for a simple transparent AHK GUI that will be toggled on with double "Right Click AND HOLD" for full screen Handwriting Recognition (possibly through Inkedit???).

Sorry if I'm asking a lot (sorry...), but I've search for all of this for around a week + 1/2 to 2 weeks before making this post and I simply cannot do it at my newbie skill level.

Here is the code below


Code: Select all

#MaxThreadsPerHotkey 4

*RButton::
If !TRButton
	SetTimer, TRButton, 
TRButton++
Return
TRButton:
If GetKeyState(rbutton,"P") ;Press and hold
	Send, ("") ;This is intentional. I have another software that uses Right Click Hold. However, I don't know if it would work if I did assign a function because of the problem with the MButton Below...


Else if TRButton = 2 ;Double Tap...Works...
send % "{Alt " ((a:=!a) ? "up" : "down") "}"

Else If TRButton = 1 ;Single Tap...Works...
	MouseClick, right

else
KeyWait, RButton 
TRButton = 

Return


*MButton::
If !TMButton
	SetTimer, TMButton, -300
TMButton++
Return

TMButton:
If GetKeyState("Mbutton","p") and TMButton !=  ;Press and hold...Does not work...
	Send MButton

Else if TMButton = 2 ;Double Tap...Works...
send % "{Shift " ((s:=!s) ? "up" : "down") "}" 

Else If TMButton = 1  ;Single Tap
send % "{Ctrl " ((c:=!c) ? "up" : "down") "}" ;It works, but it also activates when I hold the MButton, which is not what I want it to do 


KeyWait, MButton
TMButton = 

Return




;This is my failed attempt to map the eraser button on the surface pen without the need of another software to change the buttons 1st before AHK can affect the pen
<#F20::send % "{Ctrl " ((t:=!t) ? "up" : "down") "}"
return
<#F19::send % "{Shift " ((t:=!t) ? "up" : "down") "}"
return
<#F18::MButton
return
As you can see, I don't have a 4th function (Double Tap AND HOLD) and no GUI for Handwriting Recognition. Any help at all is a big help and greatly appreciated.

[Mod edit: Moved to 'Ask For Help']

User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

Re: Need Help with Surface Pen (4 functions for 1 Button, including Toggles)

Post by evilC » 29 Jul 2019, 10:34

Forgetting for the moment about your issues detecting multi-tap, are you saying that the surface pen is sending normal mouse left/right/middle click?
If so, I take it that you wish to rebind these actions ONLY when coming from the surface pen, but NOT when coming from your normal mouse?
If this is the case, then AHK hotkeys cannot be used to do this - AHK hotkeys cannot differentiate between devices.
However, I have two solutions that can potentially solve your problem(s)

1) TapHoldManager (THM) - a library to detect multi-tap, multi-tap-and-hold etc
2) AutoHotInterception (AHI) - a library that works with the Interception device driver to allow you to respond to (and block / alter) input coming from a specific device

THM works with AHI, so you could potentially use both of the above together to do what you want

Phazor
Posts: 10
Joined: 28 Jul 2019, 18:15

Re: Need Help with Surface Pen (4 functions for 1 Button, including Toggles)

Post by Phazor » 29 Jul 2019, 21:07

Thank you for your help. I would prefer just to use the pen output, but if AHK isn't able to do this, then I will use mouse input instead. I looked at the THM code and I know it will work for me, but I don't have the skill level to understand it or use it. I also left a message in the other THM thread using the code example you provided but I can't seem to get it to work and I'm not sure why... Thanks for your help.

tfpp
Posts: 2
Joined: 27 Dec 2020, 03:28

Re: Need Help with Surface Pen (4 functions for 1 Button, including Toggles)

Post by tfpp » 27 Dec 2020, 03:43

Hi Phazor,

Have you managed to solve your double click issue?
I too am trying to reprogram the surface pen side button to perform an undo when double clicked.

EvilC suggested THM & AHI, but are they a bit beyond my simple understanding of what the code does.

Post Reply

Return to “Ask For Help”