Surface Pro 7+ Slim Pen Script

Post your working scripts, libraries and tools for AHK v1.1 and older
yankoshefich
Posts: 1
Joined: 06 May 2021, 09:06

Surface Pro 7+ Slim Pen Script

10 May 2021, 12:41

After A LOT OF RESEARCH!

Here is a working script for Surface Pen Users for AutoHotKey 1.1.33.08:
Double click eraser (#F19): Show/Hide Touch Keyboard
Hold Eraser (#F18): Show start menu
Click eraser (#F20): hold RMB/release RMB (needed to me for Disco Elysium game)

Checked and solved CRAZY AMOUNT issues:
- Not working scripts without activating AutoHotKey window (first line solved to me)
- Touch keyboard not showing/hiding with AUTOHIDE task bar (solved)
- Little tweaks for better showing/hiding keyboard

Based on a lot examples. Best working for me - use as you want and if you optimize something or make some cool features - post here!

PS. Also - dont forget to switch off in pen settings default apps.

Code: Select all

#IfWinExist, ahk_class Shell_TrayWnd
{
#F18::Send, {Ctrl up}{LWin}
	return

#F19::
	
	if (WinActive(ahk_class IPTip_Main_Window)=0 OR tabtipDeactivate=true) {
		tabtipDeactivate:=false
		;show task bar (keyboard not shown if task bar is autohuded)
		WinShow ahk_class Shell_TrayWnd
		WinActivate ahk_class Shell_TrayWnd	
		;show keyboard
		ToggleTouchKeyboard()
	} else {
	WinShow ahk_class Shell_TrayWnd
		;hide keyboard
		PostMessage,0x112,0xF060,,,ahk_class IPTip_Main_Window
		tabtipDeactivate:=true
	}
	return
	
#F20::
	clickState:=not clickState
	If (clickState) {
	Click, Down Right
	} else {
	Click, Up Right
	}
	return
}

ToggleTouchKeyboard()
{
  ; Translated to AHK from https://stackoverflow.com/a/39385492
  Shell_TrayWnd := FindWindowEx( 0, 0, "Shell_TrayWnd")
  TrayNotifyWnd := FindWindowEx( Shell_TrayWnd, 0, "TrayNotifyWnd")
  TIPBand := FindWindowEx( TrayNotifyWnd, 0, "TIPBand")
  if (!TIPBand or ErrorLevel)
  {
    MsgBox % "Could not get TIPBand. ErrorLevel: " ErrorLevel
  }
  else
  {	
		PostMessage, 0x201, 1, 65537, , ahk_id %TIPBand%
		PostMessage, 0x202, 1, 65537, , ahk_id %TIPBand%
  }
}

FindWindowEx( hwnd_parent, hwnd_child, str_class, p_title=0 )
{
  if ( p_title = 0 )
    type_title = UInt
  else
    type_title = Str
  return, DllCall( "FindWindowEx"
                   , UInt, hwnd_parent
                   , UInt, hwnd_child
                   , Str, str_class
                   , type_title, p_title )
}

joch
Posts: 2
Joined: 18 Dec 2021, 01:28

Re: Surface Pro 7+ Slim Pen Script

24 Dec 2021, 18:27

It's not doing anything, I'm new to AHK so I'm not sure what I'm doing wrong. Do I need to set it up somehow or just run the script? Also, what do you mean with:
switch off in pen settings default apps.
SundayProgrammer
Posts: 143
Joined: 25 Dec 2020, 12:26

Re: Surface Pro 7+ Slim Pen Script

24 Dec 2021, 20:08

i do not have a "surface" device, but a cheap windows tablet.

so i changed it like this below.

Code: Select all

Enter & Capslock::ToggleTouchKeyboard()
Enter::Send, {Enter}

ToggleTouchKeyboard()
{
  ; Translated to AHK from https://stackoverflow.com/a/39385492
  Shell_TrayWnd := FindWindowEx( 0, 0, "Shell_TrayWnd")
  TrayNotifyWnd := FindWindowEx( Shell_TrayWnd, 0, "TrayNotifyWnd")
  TIPBand := FindWindowEx( TrayNotifyWnd, 0, "TIPBand")
  if (!TIPBand or ErrorLevel)
  {
    MsgBox % "Could not get TIPBand. ErrorLevel: " ErrorLevel
  }
  else
  {	
		PostMessage, 0x201, 1, 65537, , ahk_id %TIPBand%
		PostMessage, 0x202, 1, 65537, , ahk_id %TIPBand%
  }
}

FindWindowEx( hwnd_parent, hwnd_child, str_class, p_title=0 )
{
  if ( p_title = 0 )
    type_title = UInt
  else
    type_title = Str
  return, DllCall( "FindWindowEx"
                   , UInt, hwnd_parent
                   , UInt, hwnd_child
                   , Str, str_class
                   , type_title, p_title )
}
and the touch keyboard toggle still worked flawlessly. thank you.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: hiahkforum, manbat42, ntepa and 55 guests