public static class InkInputHelper
{
public static void DisableWPFTabletSupport()
{
// Get a collection of the tablet devices for this window.
TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;
if (devices.Count > 0)
{
// Get the Type of InputManager.
Type inputManagerType = typeof(System.Windows.Input.InputManager);
// Call the StylusLogic method on the InputManager.Current instance.
object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, InputManager.Current, null);
if (stylusLogic != null)
{
// Get the type of the stylusLogic returned from the call to StylusLogic.
Type stylusLogicType = stylusLogic.GetType();
// Loop until there are no more devices to remove.
while (devices.Count > 0)
{
// Remove the first tablet device in the devices collection.
stylusLogicType.InvokeMember("OnTabletRemoved",
BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
null, stylusLogic, new object[] { (uint)0 });
}
}
}
}
}
use that class to determine if there is a physical keyboard, or a similar way that might better suit your needs.
i used this class to open and close the keyboard wherever i wanted.
class KeyboardManager
{
public static void LaunchOnScreenKeyboard()
{
var processes = Process.GetProcessesByName("osk").ToArray();
if (processes.Any())
return;
string keyboardManagerPath = "KeyboardExecuter.exe";
Process.Start(keyboardManagerPath);
}
public static void KillOnScreenKeyboard()
{
var processes = Process.GetProcessesByName("osk").ToArray();
foreach (var proc in processes)
{
proc.Kill();
}
}
public static void killTabTip()
{
var processes = Process.GetProcessesByName("TabTip").ToArray();
foreach (var proc in processes)
{
proc.Kill();
}
}
public static void LaunchTabTip()
{
Process.Start("TabTip.exe");
}
}
keep in mind the following:
i added a copy of both osk.exe AND tabtip.exe.
adding this in my program solved an issue where either tabtip or osk wouldnt work on 32/64 bits.
osk is the keyboard, tabtip is the docked version of it.
keyboardexecuter is a program i made which is used as a fallback method.
note* i can currently not test this on a touch screen device. you have to try that on your own.
for this to all work correctly i used this code in my mainwindow:
public int selectedTableNum;
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
// Disables inking in the WPF application and enables us to track touch events to properly trigger the touch keyboard
InkInputHelper.DisableWPFTabletSupport();
//remove navigationbar
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
{
var navWindow = Window.GetWindow(this) as NavigationWindow;
if (navWindow != null) navWindow.ShowsNavigationUI = false;
}));
KeyboardManager.LaunchTabTip();
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
//Windows 8 API to enable touch keyboard to monitor for focus tracking in this WPF application
InputPanelConfiguration cp = new InputPanelConfiguration();
IInputPanelConfiguration icp = cp as IInputPanelConfiguration;
if (icp != null)
icp.EnableFocusTracking();
mainFrame.Content = new LoginPage();
}
//public bool HasTouchInput()
//{
// foreach (TabletDevice tabletDevice in Tablet.TabletDevices)
// {
// //Only detect if it is a touch Screen not how many touches (i.e. Single touch or Multi-touch)
// if (tabletDevice.Type == TabletDeviceType.Touch)
// return true;
// }
// return false;
//}
i included the comments because it might be usefull to someone if there is an error.
the inputpanel configuration:
[Guid("41C81592-514C-48BD-A22E-E6AF638521A6")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInputPanelConfiguration
{
/// <summary>
/// Enables a client process to opt-in to the focus tracking mechanism for Windows Store apps that controls the invoking and dismissing semantics of the touch keyboard.
/// </summary>
/// <returns>If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
int EnableFocusTracking();
}
[ComImport, Guid("2853ADD3-F096-4C63-A78F-7FA3EA837FB7")]
class InputPanelConfiguration
{
}
i hope this might help future visitors of this question.
TextBlock
, show the virtual keyboard. – Anatoliy NikolaevTextBox
, the built-in virtual keyboard can show up, and which should be user-friendly, such as the keyboard would never cover up the input element. – user1031200