Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect tablet mode

Tags:

c#

winforms

I'm using the following code to detect if a user is in tablet mode or not. I'm on a Surface Pro and when I decouple the keyboard and make the PC into a tablet, IsTabletMode returns true (which it should.) When I use the "Tablet Mode" button without decoupling the screen, IsTabletMode always returns false. Has anyone experienced this and How can I resolve it?

/*
 * Credit to Cheese Lover
 * Retrieved From: http://stackoverflow.com/questions/31153664/how-can-i-detect-when-window-10-enters-tablet-mode-in-a-windows-forms-applicatio
 */
public static class TabletPCSupport
{
   private static readonly int SM_CONVERTIBLESLATEMODE = 0x2003;
   private static readonly int SM_TABLETPC = 0x56;

   private Boolean isTabletPC = false;

   public Boolean SupportsTabletMode { get { return isTabletPC; }}

   public Boolean IsTabletMode 
   {
       get
       {
           return QueryTabletMode();
       }
   }

   static TabletPCSupport ()
   {
        isTabletPC = (GetSystemMetrics(SM_TABLETPC) != 0);
   }

   [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "GetSystemMetrics")]
   private static extern int GetSystemMetrics (int nIndex);

   private static Boolean QueryTabletMode ()
   {
       int state = GetSystemMetrics(SM_CONVERTIBLESLATEMODE);
       return (state == 0) && isTabletPC;
   }
}
like image 760
S. Walker Avatar asked Mar 30 '17 00:03

S. Walker


People also ask

How do I know if I am in 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?

First, tap or click on the Action Center icon present in the taskbar and then select Tablet mode to enable it. Alternatively, use the keyboard shortcut Winkey + A to activate it.

Why is my laptop in tablet mode?

By default, your computer automatically turns on Tablet mode when it detects the notebook in your hand, even if you don't wish to enable it. To set it manually according to your usage, you can try these settings. Input Tablet mode in your Start menu search bar and select the Best match to open the Settings app.


1 Answers

Edit 2: The SM_TABLETPC is only supported by Windows XP Tablet PC Edition and Windows Vista. There doesn't seem to be any reference to Windows 10 here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms700675(v=vs.85).aspx

You can use this: GetSystemMetrics(SM_CONVERTIBLESLATEMODE). A “0” returned means it is in tablet mode. A “1” returned means it is in non-tablet mode. https://software.intel.com/en-us/articles/how-to-write-a-2-in-1-aware-application

Can you replace the QueryTabletMode method with this:

   private static Boolean QueryTabletMode ()
   {
       int state = GetSystemMetrics(SM_CONVERTIBLESLATEMODE);
       return (state == 0);
   }

Edit: You might need to check this periodically as there's no event to see if the PC's tablet mode was turned on

like image 112
SP1062 Avatar answered Oct 27 '22 19:10

SP1062