Hi,
I have some problems with focussing Elements with my virtual keyboard (wpf).
Its a litte bit strange because I have started programming the virtual keyboard first in a project.
In this project the keyboard works very well, it's always topmost and it don't lost the focus when I choose some element to write in some text :).
I have a second project and imported the keyboard source files into the new project.
But it's not working in my "window1", with other Programs (Firefox,Windows Command Line etc.) its still working.
I've set window1 topmost to false and the osk window to true.
Please help.
Greetings
Update 1:
Hi,
thanks for you reply.
Here's the code sample:
//OSK Window
<pre lang="xml"><Window x:Class="OSKSample.OSK_Window"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="OSK_Window" Height="120" Background="DarkGray" MinWidth="800" Opacity="0.8" Topmost="True" WindowStyle="None" Initialized="OSK_Window_Initialized" Focusable="False" ShowInTaskbar="False" AllowsTransparency="True" WindowStartupLocation="Manual" Loaded="Window_Loaded" ResizeMode="NoResize" WindowState="Normal">
<Grid Name="keyGrid" Focusable="False">
<Grid.RowDefinitions>
<RowDefinition Height="192*"/>
</Grid.RowDefinitions>
</Grid>
</Window>
public OSK(Window parent)
{
this.parentWindow = parent;
this.setupKeyboardControl();
}
public OSK(IInputElement elementToFocusOn)
{
this.focusedInputElement = elementToFocusOn;
this.setupKeyboardControl();
}
//So, I'm sending the keys with this way...
void button_Click(object sender, RoutedEventArgs e)
{
String sendString = "";
try
{
e.Handled = true;
sendString = ((Button)sender).CommandParameter.ToString();
if (!String.IsNullOrEmpty(sendString))
{
if (sendString.Length > 1)
{
sendString = "{" + sendString + "}";
}
if (this.focusedInputElement != null)
{
Keyboard.Focus(this.focusedInputElement);
this.focusedInputElement.Focus();
}
System.Windows.Forms.SendKeys.SendWait(sendString);
}
}
catch (Exception)
{
Console.WriteLine("Taste {0} konnte nicht gesendet werden", sendString);
}
}
Get Window to focus it
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
if (this.parentWindow != null)
{
IntPtr HWND = new WindowInteropHelper(this.parentWindow).Handle;
int GWL_EXSTYLE = (-20);
GetWindowLong(HWND, GWL_EXSTYLE);
SetWindowLong(HWND, GWL_EXSTYLE, (IntPtr)(0x8000000));
}
}
So far I still don't understand why it's working when I start the osk separately.