Enable tablet mode in Windows 10 via code?

I read various ways to determine how a Windows 10 device is in Tablet Mode, primarily below:

How to determine when Window 10 goes into tablet mode in a Windows Forms application?

I would like to enable / disable Tablet mode via code (.Net C #), but I can not find any resources to achieve this. Ive tried to change the registry key and send HWND_BROADCAST that a change has occurred, but this does not trigger the change in tablet mode.

Ive also tried using applications like Spy ++, but could not see the messages sent.

Is there a way to do this?

+6
source share
2 answers

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

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

Enable: 1 or disable 0

Since I had a problem with my WPF application not appearing when launched in tablet mode, I used the AutoHotKey script. You can also create .exe. 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 
+1
source

Swap in here - you need to focus on samples for user interaction mode.

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

0
source

All Articles