Remap Surface Pen side button to hover right click

Post your working scripts, libraries and tools for AHK v1.1 and older
Rezzer
Posts: 2
Joined: 11 Apr 2017, 12:45

Remap Surface Pen side button to hover right click

11 Apr 2017, 13:50

TL;DR: This script will remap the Surface Pen's side button so that it can do hover-right click. It's based on scripts provided by Justice from http://www.tabletpro.net.

Hello

I recently bought a Surface Book and found the whole "hold side button + tap + release" thing very annoying (especially coming from a Surface Pro 2, where the side button can do a hover right click). Plus, it was also messing my workflow in Blender and Photoshop.

Anyway, after searching the web, I couldn't find a stable solution (RadialMenu works; but it also crashes frequently). Finally, I contacted Justice from Tablet Pro and he generously shared scripts and knowledge that made this possible. Now I can do hover right click using the side button on my Surface Pen (I've only tried this on the Surface Book; but it probably works on the Surface Pro 4 too). The script uses AHKHID, so you'll need that too.

I'm still testing this script; but it seems to work fine (Alt + Right hover click on Photoshop resizes the brush, Right hover click and drag works too; but I haven't tried using the Ctrl or Shift keys yet). So I'd be interested to see what other people can do to improve this script.

Finally, AutoHotKey is great! Thanks to everyone involved in it!

[Update: After some more testing I found some bugs related to the Ctrl, Shift and Alt keys. I've posted the fixed version below]
Last edited by Rezzer on 15 Apr 2017, 14:39, edited 2 times in total.
Rezzer
Posts: 2
Joined: 11 Apr 2017, 12:45

Re: Remap Surface Pen side button to hover right click

15 Apr 2017, 14:37

Thanks! I actually found some bugs related to the interaction of the Ctrl, Shift and Alt keys with the remapped right-click. I fixed the problems and here's the updated script:
hover-right-click.ahk
(3.97 KiB) Downloaded 2775 times
User avatar
SnowFlake
Posts: 368
Joined: 28 Apr 2015, 05:41
Contact:

Re: Remap Surface Pen side button to hover right click

15 Apr 2017, 14:56

also you should link to: #include AHKHID.ahk so they know were to downlad the file/script.
:yawn:
unimplode
Posts: 2
Joined: 06 Jul 2017, 10:14

Re: Remap Surface Pen side button to hover right click

06 Jul 2017, 12:39

This script is a small miracle (and the saving grace of an expensive n-trig based tablet I just bought). Thank you!
unimplode
Posts: 2
Joined: 06 Jul 2017, 10:14

Re: Remap Surface Pen side button to hover right click

09 Jul 2017, 15:40

Actually I've been playing with it now for a few days, trying to make it work smoothly on a Vaio Z canvas. Going through your code I see the following:

Code: Select all

; Set up other constants
; USAGE_PAGE and USAGE might change on different devices. 13/2 works for 
; the Surface Pen
WM_INPUT := 0xFF
USAGE_PAGE := 13
USAGE := 2
The script works on my machine but there are some unexpected behaviours. How would I go about finding the right constants (USAGE_PAGE and USAGE) for my device?
Landis

Re: Remap Surface Pen side button to hover right click

19 Jul 2017, 00:46

This is epic!! I tested it with New Wacom Ink Stylus and it works great on Surface Book. Only question is if anyone knows how to remap the rightclick to the other side switch button on Ink stylus (yes it has 2 side switches just like regular wacom pen!!) ...and...with that in mind how to get the other side switch button to be mapped to middle click. Then we are in business!!
Landis

Re: Remap Surface Pen side button to hover right click

19 Jul 2017, 01:22

Ok, so I figured out how to change the bottom side button on the new Wacom Bamboo Ink pen to be middle click which is half of the problem..now I just need to figure out what the top side button registers as (new to ahk so not sure what to run to find out what the top side button is labeled as when pressed) so that I can map it to right click.
Manuel

Re: Remap Surface Pen side button to hover right click

25 Jul 2017, 16:20

@Landis: Did you find a solution? Just got my Bamboo Ink for my Surface 4 Pro and was super disappointed that it doesn't work like a normal Wacom pen. Thinking about instantly sending it back.
Post

Security error on Forum

26 Jul 2017, 14:37

I am not sure if this is the right board, but I couldn't find a better one. Anyways, the post in Scripts and Functions called Remap Surface Pen side button to hover right click (https://autohotkey.com/boards/viewtopic.php?f=6&t=30422) gives me a security warning in chrome, one for phishing and one for missing https. I found this very weird, because this was the only post with that problem. Anyways, can someone check this out?
VinceBiwer
Posts: 1
Joined: 27 Jul 2017, 15:31

Re: Remap Surface Pen side button to hover right click

27 Jul 2017, 15:39

Manuel wrote:@Landis: Did you find a solution? Just got my Bamboo Ink for my Surface 4 Pro and was super disappointed that it doesn't work like a normal Wacom pen. Thinking about instantly sending it back.
Manuel wrote:@Landis: Did you find a solution? Just got my Bamboo Ink for my Surface 4 Pro and was super disappointed that it doesn't work like a normal Wacom pen. Thinking about instantly sending it back.
I've found an app called radial menu. in it you can remap the two button on the bamboo ink to whatever button you like.

here is a link to the app: http://radialmenu.weebly.com/download.eeeeee0

just go to the remapping option and there should be a stylus menu option.
imagineandfeel

Re: Remap Surface Pen side button to hover right click

17 Dec 2017, 05:03

I followed the instructions included in the AHK, but for some reason I get the following error.
Error at line 44.
Line Text: global PEN_NOT_HOVERING: =0x0
Error: This line doesn't contain a Recognized action.
Is it because I'm using the newer surface pen?
Guest

Re: Remap Surface Pen side button to hover right click

09 Jan 2018, 03:54

Landis wrote:Ok, so I figured out how to change the bottom side button on the new Wacom Bamboo Ink pen to be middle click which is half of the problem..now I just need to figure out what the top side button registers as (new to ahk so not sure what to run to find out what the top side button is labeled as when pressed) so that I can map it to right click.
I managed to do what you did, but I am trying to map the top side button to right click as well. Have you found a way to do it ?
TestEagle
Posts: 1
Joined: 26 Jul 2018, 06:22

Re: Remap Surface Pen side button to hover right click

26 Jul 2018, 06:32

Rezzer wrote:TL;DR: This script will remap the Surface Pen's side button so that it can do hover-right click. It's based on scripts provided by Justice from http://www.tabletpro.net.

Hello

I recently bought a Surface Book and found the whole "hold side button + tap + release" thing very annoying (especially coming from a Surface Pro 2, where the side button can do a hover right click). Plus, it was also messing my workflow in Blender and Photoshop.

Anyway, after searching the web, I couldn't find a stable solution (RadialMenu works; but it also crashes frequently). Finally, I contacted Justice from Tablet Pro and he generously shared scripts and knowledge that made this possible. Now I can do hover right click using the side button on my Surface Pen (I've only tried this on the Surface Book; but it probably works on the Surface Pro 4 too). The script uses AHKHID, so you'll need that too.

I'm still testing this script; but it seems to work fine (Alt + Right hover click on Photoshop resizes the brush, Right hover click and drag works too; but I haven't tried using the Ctrl or Shift keys yet). So I'd be interested to see what other people can do to improve this script.

Finally, AutoHotKey is great! Thanks to everyone involved in it!

[Update: After some more testing I found some bugs related to the Ctrl, Shift and Alt keys. I've posted the fixed version below]
Mate I've been busting my hump all day trying to get a dell PN338M pen working on my 2-in-1 laptop and I started looking into maybe macros/keystroke options and happened to come across this thread, sorry to dig up and old thread but I had to say a big thanks, I used your file and instructions and it worked perfectly!

I've got very little know how in this area, but I'd love to do a bat file or whatever so it runs on start-up, if anyone can assist that would be awesome, if not this has been a massive help anyway, I can now clone (by using button for right click) in paintshop pro now and it's made this lappy exactly what I needed without having to buy other items etc. Again, massive thanks!
aunt-lydia
Posts: 14
Joined: 30 Jul 2018, 04:52

Re: Remap Surface Pen side button to hover right click

30 Jul 2018, 09:11

Hi, thanks Rezzer so much for sharing this! I am using Surface Book 2 Surface Pen with one side button, and I tried the script and it works for me, even if I turn on #Warn, and get the error message too,
imagineandfeel wrote:I followed the instructions included in the AHK, but for some reason I get the following error.
Error at line 44.
Line Text: global PEN_NOT_HOVERING: =0x0
Error: This line doesn't contain a Recognized action.
but it doesn't affect the function and usage. I figured also, it works with other key mappings as well, I tried it with left click, windows key and copy and paste. Find this place in the script

Code: Select all

; This is where we remap the side button to the right-click events.
PenCallback(input, lastInput) {
    if (input = PEN_2ND_BTN_HOVERING And lastInput = PEN_HOVERING) {
	SendModifierKeys()	
	Send {RButton Down}
    }

    if (input = PEN_HOVERING And lastInput = PEN_2ND_BTN_HOVERING) {
	SendModifierKeys()
	Send {RButton Up}
    }
}
and replace the {RButton Down} and {RButton Up} with desired action. (For example, {LButton Down} and {LButton Up} for the left mouse button, or {LWin Down} and {LWin Up} for the windows key. Personally, I find the copy & paste function useful, especially in tablet mode.

Code: Select all

; This is where we remap the side button to the Copy/Paste events.
PenCallback(input, lastInput) {
    if (input = PEN_2ND_BTN_HOVERING And lastInput = PEN_HOVERING) {
	SendModifierKeys()	
	Send {LControl Down}{c}{LControl Up} 	; select object to copy, then press and hold button, move away from the screen and release button
    }

    if (input = PEN_HOVERING And lastInput = PEN_2ND_BTN_HOVERING) {
	SendModifierKeys()
	Send {LControl Down}{v}{LControl Up}	; select desired destination, keep pen away from screen, press and hold button, hover pen to screen and release button
    }
}
If you wanna use it, replace the above script in the respective place of the original script!

Thanks again for sharing the script, and have fun =)

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 103 guests