Reputation: 335
I am working on a UI for a Windows 8.1 tablet, which has a full version of Windows on it. There is a keyboard icon at the bottom of windows 8.1, which brings up a keyboard, and I want that to automatically trigger after clicking a numericUpDown box. I then would also like it to close after leaving or clicking off of the box.
I am basically just trying to focus it when it is clicked, but this does not seem to bring up the keyboard. Also, note, I am setting some other numericUpDown
box to the one in the function so I can call it outside, so I hope that doesn't make it difficult to see what's going on, let me know if you need any clarifications and thank you for the help. Here is what I have so far:
copiedNUD.Click += CopiedNudPass_Focus;
//copy copied nud
CopiedNudPass = copiedNUD;
...
void CopiedNudPass_Focus(object sender, EventArgs e)
{
CopiedNudPass.Focus();
}
I tried looking around a bit, but some of the solutions weren't too clear to me. I really appreciate the help. Thank you.
Upvotes: 1
Views: 2993
Reputation: 13516
This worked for me (in Java & eclipse RCP)
text.addFocusListener(new FocusListener()
{
@Override
public void focusLost(FocusEvent arg0)
{
LogUtil.logInfo("Closing OSK");
try
{
if(Settings.getBoolean(Settings.OSK_USETABTIP)) {
Runtime.getRuntime().exec("cmd /c taskkill /IM tabtip.exe");
} else {
Runtime.getRuntime().exec("cmd /c taskkill /IM osk.exe");
}
}
catch (IOException e)
{
LogUtil.logError(e.toString());
}
}
@Override
public void focusGained(FocusEvent arg0)
{
try
{
String sysroot = System.getenv("SystemRoot");
if(Settings.getBoolean(Settings.OSK_USETABTIP)) {
LogUtil.logInfo("Opening TabTip");
ProcessBuilder pb = new ProcessBuilder("C:/pathtotabtip/tabtip.exe");
pb.start();
} else {
LogUtil.logInfo("Opening OSK");
ProcessBuilder pb = new ProcessBuilder(sysroot + "/system32/osk.exe");
pb.start();
}
}
catch (Exception e)
{
LogUtil.logError(e.toString());
}
}
});
Upvotes: 0
Reputation: 335
Here is a better closing function:
Here is my new close code:
//Close keyboard
void CopiedNudPass_LostFocus(object sender, EventArgs e)
{
Version win8version = new Version(6, 2, 9200, 0);
if (Environment.OSVersion.Version >= win8version)
{
uint WM_SYSCOMMAND = 274;
uint SC_CLOSE = 61536;
IntPtr KeyboardWnd = FindWindow("IPTip_Main_Window", null);
PostMessage(KeyboardWnd.ToInt32(), WM_SYSCOMMAND, (int)SC_CLOSE, 0);
}
}
I also had to add a reference to WindowsBase and add external functions to the project. The steps and additional code are in the url I linked to in this post. Here's how you add a reference for WindowsBase to get using System.Windows.Interop; to work:
Upvotes: 1
Reputation: 335
I figured it out. Here is my code specifically for a tablet with window 8 or higher:
copiedNUD.Click += CopiedNudPass_Focus;
//copy copied nud
CopiedNudPass = copiedNUD;
...
//Launch keyboard
void CopiedNudPass_Focus(object sender, EventArgs e)
{
Version win8version = new Version(6, 2, 9200, 0);
if (Environment.OSVersion.Version >= win8version)
{
string progFiles = @"C:\Program Files\Common Files\Microsoft Shared\ink";
string keyboardPath = Path.Combine(progFiles, "TabTip.exe");
Process.Start(keyboardPath);
}
}
//Close keyboard
void CopiedNudPass_LostFocus(object sender, EventArgs e)
{
Version win8version = new Version(6, 2, 9200, 0);
if (Environment.OSVersion.Version >= win8version)
{
Process[] oskProcessArray = Process.GetProcessesByName("TabTip");
foreach (Process onscreenProcess in oskProcessArray)
{
onscreenProcess.Kill();
}
Refresh();
}
}
My only problem right now is that when the keyboard closes my main form in the background gets cut off and I tried to refresh it using Refresh(); , but that did not seem to work :(.
Upvotes: 2