Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Tablet Mode on Windows 10 through Code?

Tags:

c#

.net

windows

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?

like image 420
gdbgeek Avatar asked Aug 06 '15 20:08

gdbgeek


People also ask

How do I force tablet mode?

Tablet mode makes Windows 10 more touch-friendly when using your device as a tablet. Select action center on the taskbar (next to the date and time), and then select Tablet mode to turn it on or off.

What is the shortcut for tablet mode in Windows 10?

Solution. Press the Windows key + A to launch Action Center. Click the Tablet Mode quick action tile. Manually turn the tablet mode on or off.

How do I turn off tablet mode in CMD?

Step 1: In the Run interface, input cmd and click OK. Step 2: Type shutdown /s /f /t 0 in the Command Prompt window and press Enter. Then, your device will shut down immediately. After a few minutes, restart your PC to check if you easily turn off Tablet Mode.


1 Answers

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   
like image 180
J. Krue Avatar answered Oct 19 '22 08:10

J. Krue