Hello everyone,
I have an issue implementing a screen keyboard for a touch app, i need an usercontrol (for dragabble purposes) in wpf that don't steal focus from others inputs and keep it itselft always on top.
To do that i create a window whit {x:null} background and i put the usercontrol inside, then i show the window in the start of the app and i can view the "invisible" window whit the keyboard allways on top, and i can drag and drop the keyboard over the invisible window, the only problem is that i cant prevent stealing focus from other inputs, so i can't use the keyboard.
I hope you can help me.
Sorry for my bad english.
Thanks!
Matías
Here is the control XAML, it only has 3 buttons for test purposes.
<UserControl x:Class="SuperCajero.TecladoCompleto"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="200" d:DesignWidth="1024" Focusable="False">
<Grid Width="1024" Height="200" removed="Green" Focusable="False">
<Button Content="A" Height="35" HorizontalAlignment="Left" Margin="471,92,0,0" Name="btnA" VerticalAlignment="Top" Width="35" Click="btnA_Click" Focusable="False"/>
<Button Content="B" Height="35" HorizontalAlignment="Left" Margin="219,100,0,0" Name="btnB" VerticalAlignment="Top" Width="35" Click="btnB_Click" Focusable="False"/>
<Button Content="C" Height="35" HorizontalAlignment="Left" Margin="366,100,0,0" Name="btnC" VerticalAlignment="Top" Width="35" Click="btnC_Click" Focusable="False"/>
</Grid>
</UserControl>
Here is the C# code of the control that makes it draggable inside the auxiliar window
public partial class TecladoCompleto : UserControl
{
public TecladoCompleto()
{
InitializeComponent();
MakeDraggable(this, this);
}
public void MakeDraggable(System.Windows.UIElement moveThisElement, System.Windows.UIElement movedByElement)
{
bool isMousePressed = false;
System.Windows.Media.TranslateTransform transform = new System.Windows.Media.TranslateTransform(0, 0);
moveThisElement.RenderTransform = transform;
System.Windows.Point originalPoint = new System.Windows.Point(0, 0), currentPoint;
movedByElement.MouseLeftButtonDown += (a, b) =>
{
isMousePressed = true;
originalPoint = ((System.Windows.Input.MouseEventArgs)b).GetPosition(moveThisElement);
};
movedByElement.MouseLeftButtonUp += (a, b) => isMousePressed = false;
movedByElement.MouseLeave += (a, b) => isMousePressed = false;
movedByElement.MouseMove += (a, b) =>
{
if (!isMousePressed) return;
currentPoint = ((System.Windows.Input.MouseEventArgs)b).GetPosition(moveThisElement);
transform.X += currentPoint.X - originalPoint.X;
transform.Y += currentPoint.Y - originalPoint.Y;
};
}
private void btnA_Click(object sender, RoutedEventArgs e)
{
WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.VK_A);
}
private void btnB_Click(object sender, RoutedEventArgs e)
{
WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.VK_B);
}
private void btnC_Click(object sender, RoutedEventArgs e)
{
WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.VK_C);
}
}
Here is the auxiliar transparent window that owns the usercontrol
<Window x:Class="SuperCajero.AuxWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:SuperCajero"
Title="AuxWindow" WindowStyle="None" Topmost="True" AllowsTransparency="True" removed="{x:Null}" Focusable="False" >
<Grid>
<controls:TecladoCompleto HorizontalAlignment="Center" VerticalAlignment="Bottom" Focusable="False"/>
</Grid>
</Window>