I need to show, and input some text in xbox-like onscreen keyboard. Sadly, when I call Guide.BeginShowKeyboardInput, there is only some funny textbox shown, and i must fill it via keyboard. I know, that on PC iv very normal to use keyboard, but in my case i MUST enter text via gamepad, using xbox on screen keyboard.
Is there any way to achieve this? To call xbox onscreen keyboard on PC?
If you need one for like a touchscreen monitor you could do
using System.Diagnostics;
using System.IO;
then use this function
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) + Path.DirectorySeparatorChar + "osk.exe");
but if you need it to work with like an xbox controller you will probably need to build your own
No. It was a design decision (documented here) to give the end user control of the keyboard being invoked. Therefore, the end user has to touch a text box (or the like) to invoke the virtual on-screen keyboard.
Check this text form this link
Blockquote User-driven invocation
The invocation model of the touch keyboard is designed to put the user in control of the keyboard. Users indicate to the system that they want to input text by tapping on an input control instead of having an application make that decision on their behalf. This reduces to zero the scenarios where the keyboard is invoked unexpectedly, which can be a painful source of UI churn because the keyboard can consume up to 50% of the screen and mar the application's user experience. To enable user-driven invocation, we track the coordinates of the last touch event and compare them to the location of the bounding rectangle of the element that currently has focus. If the point is contained within the bounding rectangle, the touch keyboard is invoked.
Blockquote This means that applications cannot programmatically invoke the touch keyboard via manipulation of focus. Big culprits here in the past have been webpages—many of them set focus by default into an input field but have many other experiences available on their page for the user to enjoy. A good example of this is msn.com. The website has a lot of content for consumption, but happens to have a Bing search bar on the top of its page that takes focus by default. If the keyboard were automatically invoked, all of the articles located below that search bar would be occluded by default, thus ruining the website's experience on tablets. There are certain scenarios where it doesn't feel great to have to tap to get the keyboard, such as when a user has started a new email message or has opened the Search pane. However, we feel that requiring the user to tap the input field is an acceptable compromise.
Check out: http://classes.soe.ucsc.edu/cmps020/Winter08/lectures/controller-keyboard-input.pdf
You might find your answer in here, It has all information about the input of a gamepad and such.
There is a good guide on how to do this here:
static public string GetKeyboardInput()
{
if (HandleInput.currentState.IsButtonDown(Buttons.B))
{
useKeyboardResult = false;
}
if (KeyboardResult == null && !Guide.IsVisible)
{
string title = "Name";
string description = "Pick a name for this game";
string defaultText = "Your name here";
pauseType = PauseType.pauseAll;
KeyboardResult = Guide.BeginShowKeyboardInput(HandleInput.playerIndex, title,
description, defaultText, null, null);
useKeyboardResult = true;
pauseType = PauseType.pauseAll;
}
else if (KeyboardResult != null && KeyboardResult.IsCompleted)
{
pauseType = PauseType.none;
KeyboardInputRquested = false;
string input = Guide.EndShowKeyboardInput(KeyboardResult);
KeyboardResult = null;
if (useKeyboardResult)
{
return input;
}
}
return null;
}
And your Update method should contain something like this:
if (KeyboardInputRequested)
{
string result = GetKeyboardInput();
}
if (result != null)
{
//use result here
}
It is unlikely that the on-screen keyboard was packaged in the XNA DLLs for PC, but if you really want to find out, you could research a free .NET decompiling program (such as ILSpy) and look through it.
Also, you can't use the chatpad either. I would recommend either making your own on-screen keyboard that is usable by a controller, or maybe, if you can, using the MonoGame framework (an open-source version of XNA), and modifying it to have an on-screen keyboard on Windows.
You could also make a separate program that acts as a virtual keyboard controlled by the controller.
Related
We have a Xamarin app (Android) that at one stage opens up a web view (Webkit.Webview not Forms.Webview). This directs the user to a page on a third party site which has been set up for us.
Firstly - on certain input fields the keyboard which shows up is the wrong one - we are expecting a dismissable keyboard (i.e. "Done" in the bottom corner, not a "Submit"). I know this can be changed but not sure what is the correct way to do this. Does it have to be the metadata/text inputs on the web page that is changed? If so - what needs to be modified per text box entry on the html of the page? Just the type? i.e:
<input type="email">
Secondly, rather than wait for the third party to fix the page, is there a way we can force the webview to always open a certain keyboard type?
We have an option of intercepting the keyboard key presses and trying to dismiss the keyboard on return press at the minute. But would prefer not to put a hack in that intercepts every key press.
Appreciate the help, not sure what the way forward is here.
Thanks
From the comments: To your second question about forcing a keyboard button, you can check out this link which describes how to override OnCreateInputConnection to specify the Keyboard Enter Button type.
public class MyWebView : WebView {
...
public override IInputConnection OnCreateInputConnection (EditorInfo outAttrs) {
var inputConnection = base.OnCreateInputConnection (outAttrs);
// outAttrs.ImeOptions in Xamarin only allows ImeFlags but it also should allow ImeActions
outAttrs.ImeOptions = outAttrs.ImeOptions | (ImeFlags)ImeAction.Next;
return inputConnection;
}
}
That will not dismiss your keyboard when tapped though since it is meant to take the user to the next input. Hopefully someone else can come along and either provide a better answer or give a good way to dismiss the keyboard in this situation without hacking something together.
I'm developing a game using Xamarin/Monogame and I need to open the keyboard on a mobile device when they click on my input control. I recognize that I can capture input using Keyboard.GetState() when I'm using the emulator and my keyboard, but real users will have physical devices, and I need to open the on-screen keyboard for them to enter in information. I don't see anything in any documentation describing this, but it's hard to believe I'm the first person to run into this. I've looked through Xamarin/Monogame's docs on input and I've read this StackOverflow article. Let me know if you need more information to help solve this. Thanks in advance for any help.
After much digging I was able to figure out the solution. I'll first start by explaining how I got there:
I stopped thinking "how do I display the on-screen keyboard in Mono?" and started thinking "how do you display the keyboard on an Android device?" This lead me to this article which was perfect; Xamarin and Android. Here's the relevant snippets:
Showing the soft input (on-screen keyboard)
var pView = game.Services.GetService<View>();
var inputMethodManager = Application.GetSystemService(Context.InputMethodService) as InputMethodManager;
inputMethodManager.ShowSoftInput(pView, ShowFlags.Forced);
inputMethodManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);
Some key notes about this:
The View class is Android.Views.View
The InputMethodManager class is Android.Views.InputMethods.InputMethodManager
This code is called from within an Activity class, so Application refers to a property on that class (this.Application)
game is your game class (in Mono) that is of type Microsoft.Xna.Framework.Game
Hiding the soft input (on-screen keyboard)
InputMethodManager inputMethodManager = Application.GetSystemService(Context.InputMethodService) as InputMethodManager;
inputMethodManager.HideSoftInputFromWindow(pView.WindowToken, HideSoftInputFlags.None);
After I solved this, the way I was capturing input (the XNA/Mono way) was not capturing this input. So I had to continue digging. While it doesn't necessarily pertain to this question, I'd like to post it here so it exists somewhere. This documentation on the Android Developers site helped me.
To capture input directly (which is what we need to do to capture to OSK input), you need to override the OnKeyPress method on the activity your game is running in. For me, this looks as follows:
public class AndroidActivity : AndroidGameActivity
{
private void OnKeyPress(object sender, View.KeyEventArgs e)
{
// do stuff with the input
}
}
Hope this helps anyone else who got stuck with this; the information was hard to find, but now that I've changed my frame of mind to "how does Android/iOS handle this thing" I've been able to locate answers more easily. Good luck!
I'm making a c# windows application that will make it possible to fully control your windows computer via a gaming controller only. Right now I'm done with mouse control coding and I'm testing for bugs. What I want next is to create a virtual keyboard which shows up when a text box in any application is clicked. For example, the android keyboard which only appears when you need it. I have searched and the only thing I have found so far is how to call a function only when the text box is in the same Form. My question is if there is a way to make a listener when a textbox is clicked for all open programs. I would appreciate any help.
You should send the code or integer between forms when user click on the textbox using code like :
public string _label3
{
get { return label3.Text; }
}
you write value and send it to other form then receive it using set method.
public string _label3
{
set { return label1.Text; }
}
Using timer to watch coming value all time or check for label1.text then, when u receive this value
using this code to open virtual Keyboard.
System.Diagnostics.Process.Start("osk.exe");
I'm building a "WPF Application" which is made to be run in the background (minimised state) and detects KeyStrokes of each and Every key on the keyboard & every Mouse Clicks.
So, my question is how to detect every keyStrokes whether app (Window) is minimised or not.
Simply, if my app is in focus then i use this code to count keystrokes.
Public int count;
protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e)
{
//base.OnKeyDown(e);
count++;
tBlockCount.Text = count.ToString();
}
I just want to do the same even if my app is minimised.
I've searched a lot and come across many suggestions like..
http://www.pinvoke.net/default.aspx/user32/registerhotkey.html
http://social.msdn.microsoft.com/Forums/vstudio/en-US/87d66b1c-330c-42fe-8a40-81f82012575c/background-hotkeys-wpf?forum=wpf
Detecting input keystroke during WPF processing
Detect if any key is pressed in C# (not A, B, but any)
Most of those are indicating towards Registering HotKeys. But I'm unable to match scenario with mine.
Any kind of suggestion are most welcome.
Although I'm not really condoning the use of a keylogger (This is what you are trying to do). I would recommend taking a look at this q/a, the section near the bottom of this article, and this article for some inspiration. These should help point in the right direction for the coding side.
What you essentially need to do is just set up an event to intercept any keys that come in from the computer, then you can gather the key and do whatever you like with it (in your case, record it)
Edit: In fact, reading the third article, it actually gives a full code snippet on how to implement and use it in WPF, so I recommend just reading that one.
I have a small tray application which registers a system-wide hotkey. When the user selects a text anywhere in any application and presses this hotkey I want to be able to capture the selected text. I'm currently doing this using AutomationElements:
//Using FocusedElement (since the focused element should be the control with the selected text?)
AutomationElement ae = AutomationElement.FocusedElement;
AutomationElement txtElement = ae.FindFirst(TreeScope.Subtree,Condition.TrueCondition);
if(txtElement == null)
return;
TextPattern tp;
try
{
tp = txtElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
}
catch(Exception ex)
{
return;
}
TextPatternRange[] trs;
if (tp.SupportedTextSelection == SupportedTextSelection.None)
{
return;
}
else
{
trs = tp.GetSelection();
string selectedText = trs[0].GetText(-1);
MessageBox.Show(selectedText );
}
This works for some apps (such as notepad, visual studios edit boxes and such) but not for all (such as Word, FireFox, Chrome, and so on.)
Anyone here with any ideas of how to be able to retreive the selected text in ANY application?
Unfortunately, there's no way to get the selected text from any arbitrary application. UI Automation works if the application supports UIA TextPattern; unfortunately, most do not. I wrote an application that tried to do this, and had a bunch of fallbacks.
I tried (pretty much in order):
UIA.TextPattern
Internet Explorer-specific (this had different implementations for IE 6,7,8,9)
Adobe Reader-specific
Clipboard
This covered 80-90% of the applications out there, but there were quite a few that still failed.
Note that restoring the clipboard has problems of its own; some applications (Office, etc.) put vendor-specific information into the clipboard that can have pointers into internal data; when you put your own info on the clipboard, the internal data gets released, and when you put the old data back, the clipboard now points to freed data, resulting in crashes. You could work around this somewhat by only saving/restoring known clipboard formats, but again, that results in odd behavior in that apps behave "wrong" instead of crashing.
UIA technology does not supported by all applications, you can try to use MSAA in some cases (like FF, Chrome, etc.) but you still will get many problems.
The best way is to save current clipboard text, send "CTRL + C" keypress message via SendMessage WinAPI function, get clipboard text, and restore initial clipboard text as Rick said.
Is it possible to look at the clipboard and make your hotkey: CTRL+C ?
You won't be able to read selected text from any application. For example some PDF files have protected content that disallows copies.