Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Stylus middle-mouse button emulation

  • Please log in to reply
4 replies to this topic
  • Members
  • 27 posts
  • Last active: Apr 08 2013 06:50 PM
  • Joined: 22 Jun 2008

I want to emulate a middle mouse button on my Surface Pro stylus; for instance, when I tap and press the stylus button without lifting the pen. The stylus is  Wacom tech with a single button (and an eraser). The link below has exactly what I want, but I can't get it to work. I don't know it I'm doing something wrong or it's a problem specific to the Surface.




Any ideas?

  • Moderators
  • 8109 posts
  • Last active: Today, 05:26 PM
  • Joined: 08 Apr 2009

Here is a script I use when I want to know what key was pressed.

Read through the script and then run it and follows the instructions.

Try the script with you normal keyboard to see how it works and detects keypresses.


Then try the script with your stylus to see if the script detects the "keys" that the stylus sends.

Perhaps you can then simulate these keypresses with AHk.

#singleinstance force
The window behind this message is the Key History Window
type a few keys '123'
               and then hit F5
Do you see them in the key history?
press the mouse button
               then hit F5 again
do you see what button was pushed?
The hotkey F1 will copy the text from the KeyHistory Window to the clipboard
KeyHistory ; Display the history info in a window.
msgbox %message%
#KeyHistory 100
;KeyHistory ; Display the history info in a window.

esc::exitapp   ; press escape key to exit script
WinGetText, clipboard, ahk_class AutoHotkey

  • Members
  • 27 posts
  • Last active: Apr 08 2013 06:50 PM
  • Joined: 22 Jun 2008

I've tried using Key History before, but unfortunately it doesn't show the stylus button presses directly. First of all, the stylus button is not shown at all; clicking it while not touching the screen shows a little circle icon appearing by the pointer, but it is not shown in the key history. Second, the left and right clicks shown are not always "true" clicks; for instance, if you touch the screen, drag, and release, it is visible as distinct press and release events, but if you tap the screen, wait, and then release without moving the pointer, it is seen by AHK as a press and immediate release (no delay) at the time that you let go.


I need a way to directly track the events of the stylus button and the true press/release events when I tap the screen. How do I get those low-level events? (Also, it would be nice to be able to track eraser-button clicks as well, which register in the key history as identical to normal taps.

  • Members
  • 81 posts
  • Last active: Apr 13 2014 08:16 PM
  • Joined: 22 May 2012

Hi haxor,


I don't own a Surface Pro but I have an EP121 and have been involved in the design of toolbars for art programs using AHK. That has involved a lot of playing around trying to remap Wacom pen buttons and has been successful on pretty much any Wacom-based tablet PC. I've found that the best way is to just do a simple remap.  Has wacom come up yet with a driver that allows you to assign different functions to the pen buttons (that's possible in Win 7 but I don't think it's yet available in Win 8, which I'm assuming your SP has)?


If not, is your pen button set to right-click? If that's the case, you can maybe just do a simple remapping like



do something



If your pen button is indeed set to right-click, then you could also explore the use of something like "Keywait" or "GetKeyState" to "do something" as long as the pen button is pressed.



Remapping the eraser on Wacom pen seems to be pretty difficult as I've found that it's usually not detected by AHK or when looking at HID devices. Maybe there is a better way around, but the only way that I have found to remap the eraser is to modify the Wacom pen settings manually (and that is probably only available with a correct Wacom driver, which you may not have). If you are interested, you can find a description of what I've found here:



Note that in this Tablet PC forum, there are a lot of Autohotkey based solutions to make your use of your tablet easier. I would suggest you explore the following:



  • Members
  • 27 posts
  • Last active: Apr 08 2013 06:50 PM
  • Joined: 22 Jun 2008

Unfortunately, there aren't any available Wacom drivers to remap the pen button or any other way of changing pen behavior. As for remapping RMB, that won't help. As I said above, the pen button doesn't actually send a right-click; a right-click is only sent if you tap while holding the button. I'd ideally like to add functionality for, say, pressing the button while pressing on the screen with the pen.