I developing an app in UWP, architecture 64x. With C#, W10 in kiosk mode.
I need to show and use only numeric keyboard for all input's into all application, but the keyboard provided by windows when i use InputScope="NumericPin" in TextBox element the NumericPin keyboard is showed, but when control lose focus for a moment the standard keyboard appears and disappears.
I already tried this, but it works just like what I have explained:
https://msdn.microsoft.com/en-us/library/windows/apps/mt280229.aspx
I also considered use an external keyboard app service and it works perfectly, but my boss say it is the last resource.
http://chessware.ch/virtual-keyboard/index.php
What i looking for is something like:
use the NumericPin keyboard as static in display every time.
the only keyboard layout available be NumericPin keyboard.
I finded this related question but says the same what me:
UWP VirtualKeyboard shows NumericPin layout in simple textbox
Thanks for everybody.
I need to show and use only numeric keyboard for all input's into all application, but the keyboard provided by windows when i use InputScope="NumericPin" in TextBox element the NumericPin keyboard is showed, but when control lose focus for a moment the standard keyboard appears and disappears.
As you said, the keyboard provided by windows and the type of keyboard is determined by InputScope property of input control. You could manually set InputScope property. However, you could not set keyboard for the input control that has not been determined InputScope property.
For your requirement, I think you could set global style for input control in Application.Resources. such as TextBox,RichEditBox etc.
<Application.Resources>
<Style TargetType="TextBox">
<Setter Property="InputScope" Value="NumericPin"/>
</Style>
</Application.Resources>
Related
I have two text-boxes, one for English and one for Russian. For ease of use purposes, I'd like to know if there's something available in c# that tells my system to switch to one of the installed keyboard layouts.
I would then plan to set a method that does this as soon as one of the text-boxes get focused.
So when the Russian box is focused, the windows Russian keyboard layout is used and vice versa.
I was searching online for a bit but I didn't find any of the sort. Since I wanted it finished early I did a workaround and just simulated the key-presses necessary to switch keyboard layouts on windows using Input-simulator. Now I am looking for a better solution.
Public Form1()
{
// I use the method when either of the text-boxes are used.
// When I find a better solution, there will obviously be two separate methods
txtRussian.GotFocus += SwitchKeyboard;
txtEnglish.GotFocus += SwitchKeyboard;
}
private void SwitchKeyboard(object sender, EventArgs e)
{
// shift alt for keyboard layout switch
sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.SHIFT,VirtualKeyCode.LMENU);
// LMENU (Left Alt) tends to still be pressed after you he finished the modified keystroke.
// So that makes any first key the user presses be the "LAlt + {a key}" instead of just a key.
// By normally simulating its press again the issue is gone
sim.Keyboard.KeyPress(VirtualKeyCode.LMENU);
}
Of course, this isn't what I'd truly want, cause whenever you alt tab in and out and refocus on a text-box, it'll just switch to the next keyboard layout installed instead of a specified keyboard layout for which the text-box is meant.
So yeah, is there a way to switch to a specified windows keyboard layout with c#?
There is the "InputLanguage" class in the System.Windows.Forms namespace.
You could use the "InputLanguage.CurrentInputLanguage" property to change the currently used keyboard layout.
There is already another post on stackoverflow about that:
C# - Automatically switch between two different IME in the same keyboard layout
However, you can only change the input language with that, but not the layout inside the language. But I think changing the input language is what you need.
If you also need to change the input layout of the language you could do so with setting the .ImeMode property of the TextBox.
In my WPF app I am using what's written below to bind a key press of the F10 key to running a method in my script named 'btn_font_click'. However obviously UWP does not support direct keybindings like this in XAML since it's universal and not designed for Windows.
Is there any way that I can get this same effect in a UWP application?
<Window.Resources>
<RoutedUICommand x:Key="cmd1"></RoutedUICommand>
</Window.Resources>
<Window.CommandBindings>
<CommandBinding Command="{StaticResource cmd1}"
Executed="btn_font_Click">
</CommandBinding>
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding Key="F10" Command="{StaticResource cmd1}"></KeyBinding>
</Window.InputBindings>
I'm using for inputting data from an RFID reader. Currently when the RFID card is scanned it presses F10, types out its data and then presses enter.
My idea is F10 sets the keyboards focus to a textbox, the script then waits for an enter press while the RFID types out its data and it then takes what's in the text box and splits it into an array for usage within the app.
If there's a better or more direct way for getting the data from within the RFID card to my array I'm open for other potential solutions.
Edit: After looking into this for a while I've found that a 'Keyboard Accelerator' would be best for this programs current functionality as I would like the RFID card to still work while the app isn't in focus. Could I get some pointers as of how to set up a Keyboard Accelerator linking an F10 key press to running my method?
If you want to set up this kind of application-wide keyboard shortcut mechanism, activators are definitely one way to go about doing it.
There is a documentation on keyboard accelerators available and this functionality is available since the Fall Creators Update. Each UIElement has a KeyboardAccelerators collection, which allows you to define keyboard accelerators which interact with it. In case of buttons and menu items invoking the specified shortcut automatically invokes the control, but to make your TextBox focused, you have to specify this behavior yourself using the Invoked event:
<TextBox>
<TextBox.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="None"
Key="F10" Invoked="KeyboardAccelerator_OnInvoked" />
</TextBox.KeyboardAccelerators>
</TextBox>
And in the event handler the TextBox is then focused:
private void KeyboardAccelerator_OnInvoked(
KeyboardAccelerator sender,
KeyboardAcceleratorInvokedEventArgs args )
{
(args.Element as Control).Focus(FocusState.Keyboard);
}
The KeyboardAcceleratorInvokedEventArgs.Element property contains a reference to our TextBox, I cast it to Control, as this is the parent of TextBox that declares the Focus method and you can potentially reuse this method on any focusable control.
Is it possible in UWP to force it to open the On Screen Keyboard (osk.exe)?
For example, in C# it is possible using System.Diagnostics.Process.Start("osk.exe");
Doing the above in UWP results in compile error saying there is no Process namespace.
I know that in Tablet mode, if I programmatically focus on a TextBox, it will show up the OnScreen keyboard.
But is it possible when in Desktop mode?
Is there a way for touchkeyboard to appear in desktop mode?
Ref the document in Keyboard interactions
Depending on the device, the touch keyboard appears when a text field or other editable text control gets focus, or when the user manually enables it through the Notification Center:
(source: s-msft.com)
Note The user might have to go to the Tablet mode screen in Settings > System and turn on "Make Windows more touch-friendly when using your device as a tablet" to enable the automatic appearance of the touch keyboard.
So the touch keyboard can appear automatically in tablet mode when users sets the input focus to a text control by using touch input. However, this won't happen in desktop mode and in UWP, there is no API to open it programmatically by now.
To show touch keyboard in desktop mode, we need the user manually enables it by clicking touch keyboard button and users can see this button by checking "Show touch keyboard button" in taskbar.
You are welcome to submit a request for this feature through UserVoice and Windows Feedback Hub app.
I was able to Show/Hide the On Screen Keyboard in Desktop Mode using:
CoreInputView.GetForCurrentView().TryShow(CoreInputViewKind.Keyboard)
Code Sample:
.xaml:
<TextBox GotFocus="TextBox_OnGotFocus" LostFocus="TextBox_OnLostFocus" InputScope="Number"/>
.xaml.cs:
private void TextBox_OnGotFocus(object _, RoutedEventArgs __)
{
CoreInputView.GetForCurrentView().TryShow(CoreInputViewKind.Keyboard);
}
private void TextBox_OnLostFocus(object _, RoutedEventArgs __)
{
CoreInputView.GetForCurrentView().TryHide();
}
Additionally, you can control the keyboard type by setting the InputScope with values like: Number, NumericPin, Text, or others:
https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Input.InputScopeNameValue
I am writing an onscreen keyboard and would like to redraw my layout as soon as keyboard layout is changed.
Currently I call:
GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), NULL));
on every key press to find out if the layout has changed. It does not work if user changes the layout by mouse, until key is pressed.
I would like to know if there is any way to get notified
when the keyboard layout of the current foreground window is changed,
so I can redraw my layout as soon as the change happens.
There is a way ...
First you need to register your application to capture foreground window changes:
Use SetWinEventHook with EVENT_SYSTEM_FOREGROUND (and WINEVENT_OUTOFCONTEXT as it's .NET) for that.
If that happens: Use your GetKeyboardLayout solution for getting the current layout of that window.
Then use a local Windows Hook (you're probably using it low-level-globally for key captures) with WH_CALLWNDPROC and the thread of the new foreground window.
Listen to WM_INPUTLANGCHANGE messages to that window to receive changes to the layout.
(You may want to unhook/rehook after another foreground change)
It looks like the keyboard layout is stored here:
HKEY_CURRENT_USER\Keyboard Layout\Preload
When I changed keyboard languages, the order of settings there changed.
So you could possibly monitor the registry entry. Here's one way:
http://www.codeproject.com/KB/system/registrymonitor.aspx
I would like to be able to programmatically emulate the keyboard
navigation for dialog boxes.
I have a custom hardware device with a keypad that I would like to use for
dialog box navigation.
I know about Focus(), but I'd rather do something that automatically
respected the tab order. By emulating the keyboard navigation I don't
have to worry about re-inventing complex behavior for each type of
control.
Does anyone know how to do this?
Thanks!
For Winforms, you want want the Control.GetNextControl() method
For WPF, you want the UIElement.MoveFocus() method
In Winforms:
Control nextControl = this.GetNextControl(myControl, true);
To simulate a tab press, I believe it's the following:
SendKeys.Send("{TAB}");
You could use P/Invoke to call the Windows API function keybd_event to simulate pressing the Tab key.
Bonus: you can use your device to enter tabs into a text editor as well! ;)