8

Ive read various way on how to detect if a Windows 10 device is in Tablet Mode, most notably the topic below;

How can I detect when Window 10 enters tablet mode in a Windows Forms application?

I would like to enable/disable Tablet Mode through code (.Net C#) but I cant find any resources to achieve this. Ive tried changing the registry key and sending a HWND_BROADCAST that a change has occurred but this doesn't initiate the change to tablet mode.

Ive also tried using Spy++ style applications but cant see the messages being sent.

Does a method exist to do this?

Community
  • 1
  • 1
gdbgeek
  • 81
  • 1
  • 2
  • I'm quite sure this method doesn't exist. – David Leitner Aug 06 '15 at 20:27
  • @DavidLeitner There has to be some event, as Microsoft has taken advantage of it in their apps. It may not be exposed in the .NET Framework, but it will exist in the WinAPI somewhere. – Gregory A Beamer Aug 06 '15 at 20:49
  • @GregoryABeamer thanks for the comments. Yes I expect it its buried in the WinAPI somewhere. I had already trawled the UWP samples and most are related to handling the change to tablet mode and not initiating it. – gdbgeek Aug 07 '15 at 00:41
  • @gdbgeek You want to force someone into tablet mode? – Gregory A Beamer Aug 07 '15 at 00:48
  • @GregoryABeamer almost correct.I have a 2-in-1 device that does not automatically switch to tablet mode when I undock the keyboard. I can detect when the keyboard is removed. When this occurs I would like to enable tablet mode. – gdbgeek Aug 07 '15 at 01:14
  • Using a windows form application I can see the message being broadcast but doing the same from my application doesnt change the mode. – gdbgeek Aug 07 '15 at 02:11
  • @gdbgeek Did you get any solution to enable tablet mode in code ? – Mohanvel V Jan 03 '17 at 09:00

2 Answers2

4

There is no real way to do this in C#. Of course you can change the registry key, but you will need a log off/on to change from or to tablet mode.

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\ImmersiveShell\TabletMode

Enable: 1 or disable 0

Since I had a problem that my WPF-App will not appear on startup with tablet mode on, I used a AutoHotKey script. You can create a .exe as well. Source: https://autohotkey.com/boards/viewtopic.php?t=15619

#NoEnv
SetBatchLines -1
ListLines Off
#NoTrayIcon 


TABLETMODESTATE_DESKTOPMODE := 0x0
TABLETMODESTATE_TABLETMODE := 0x1

TabletModeController_GetMode(TabletModeController, ByRef mode) {
    return DllCall(NumGet(NumGet(TabletModeController+0),3*A_PtrSize), "Ptr", TabletModeController, "UInt*", mode)
}

TabletModeController_SetMode(TabletModeController, _TABLETMODESTATE, _TMCTRIGGER := 4) {
    return DllCall(NumGet(NumGet(TabletModeController+0),4*A_PtrSize), "Ptr", TabletModeController, "UInt", _TABLETMODESTATE, "UInt", _TMCTRIGGER)  
}

ImmersiveShell := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}")
TabletModeController := ComObjQuery(ImmersiveShell, "{4fda780a-acd2-41f7-b4f2-ebe674c9bf2a}", "{4fda780a-acd2-41f7-b4f2-ebe674c9bf2a}")

if (TabletModeController_GetMode(TabletModeController, mode) == 0)
    TabletModeController_SetMode(TabletModeController, mode == TABLETMODESTATE_DESKTOPMODE ? TABLETMODESTATE_TABLETMODE : TABLETMODESTATE_DESKTOPMODE)

ObjRelease(TabletModeController), TabletModeController := 0
ObjRelease(ImmersiveShell), ImmersiveShell := 0 ; Can be freed after TabletModeController is created, instead   
Nathan Tuggy
  • 2,239
  • 27
  • 28
  • 36
J. Krue
  • 89
  • 8
1

Poke around in here - You will want to focus on the samples for user interaction mode.

NOTE: This is for UWP (Universal Windows Platform), aka Windows 10+, and you will need code for other versions of Windows if you are not targeting Win 10 only.

Sagar V
  • 11,083
  • 7
  • 41
  • 62
Gregory A Beamer
  • 16,342
  • 3
  • 23
  • 29