Check if software keyboard is open in Windows Phone 8? - vb.net

I want to check if the software keyboard is open in Windows Phone 8. I have found some sparse information that this is possible using CoreWindow.IsKeyboardInputEnabled, but I can't find any way to implement this. I have found sample code only for C++, which I don't understand at all.
I use VB, however I can read C# enough to figure it out if I can get a C# example.
Whatever I do I always get a null/nothing value. The following code compiles and runs, but c is 'nothing' when the app crashes at the if c.IsKeyboarInputEnabled... line.
Dim c as CoreWindow
c = CoreWindow.GetForCurrentThread
if c.IsKeyboardInputEnabled then...
I know I need to give 'c' a value, but can't figure out how. I've also tried:
Dim c as CoreWindow = New CoreWindow
which the editor flags as an error and thus won't compile.
If it's relevant, what I am trying to do is ensure my navigation is consistent. Currently, a tap on a particular screen element should close that element. However, if the keyboard is open, I want that tap to simply close the keyboard and leave the tapped item open. I believe this is the more intuitive and consistent approach for the user.
I think the only way to achieve this functionality is to know if the keyboard is open before determining what to do with any open panels.
e.g.
[when screen tapped and a popup is expanded]
If [keyboard visible] then [close keyboard] else [close tapped item]

I don't think there is any official API to detect the opening and closing of the SIP but one workaround might be to check if any of your TextBoxes have focus.
You can do this by overriding GetFocus and LostFocus for each TextBox.
To close keyboard, just set the focus to the ContentPanel(or any other grid).
Let me know if this works.

Related

Can I detect if a (node-webkit) window is visible?

I would like the user to be able to click on the system tray icon to hide a window if it is visible, or show it if it isn't. However I can't see way to detect the show/hide state of the window.
I looked here but couldn't see anything that would give me what I need. The only way seems to be to keep track of if my last call was to show() or to hide(). Is there a better way?
I've needed this myself just recently, but as far as I know the best (only?) way is to set a boolean (e.g. var showing = true;) and then on every change (including the minimize and restore events) set the boolean to the correct value. Then you could simply make an if statement when clicking on the tray icon to see if the window is showing, and if it is hide the window, otherwise show it.
Hope I helped you a bit, I'm still looking for a better way myself but this is all I have found so far.

Windows 8 Keyboard Connected event

Is there any API in Windows 8 that tells you whether there is a Keyboard connected to your device? I believe the OS should have information about this, but I am not sure that it is exposed.
I checked the Windows.Devices.Input.KeyboardCapabilities(). It only returns an object with a property keyboardPresent that equals to 1 on my touch device or non-touch device.
The problem has already been reported on stackoverflow without solution (Provide another solution but which also don't seem to work).
Maybe a work around could be to add a TextBox outside the screen and set the focus on it and register InputPane.GetForCurrentView().Showing and to see if it is fired or not. If it is you can deduce that there is no keyboard connected (and you might be able to reset the focus to the page inside the event so that the keyboard don't actually pop up) and if it don't fired that the there is a keyboard connected. That not a really good solution but might be the best available ...

How to simulate mouse clicks?

I was wondering how to create a sort of auto clicker using VB.NET.
I would basicly have the click coordinates pre-defined and the clicks, which would have to be separated by delays I guess since I want more than one to happen periodically, would happen outside of the application window (I read this envolves extra system hooks?).
The only code I have been able to find is related to clicks on the application window, which is not what I am looking for.
In short: I want to click a button on the app window, which would initiate a number of clicks on certain pre-defined screen coordinates.
Thanks in advance :)
See this discussion on social.msdn: Simulate a mouse click in a program.
Uses winapi: SetCursorPos, GetCursorPos and mouse_event.
I believe you need to P/Invoke into Windows to accomplish this.
Have a look at the SendInput function.
If you are using automate the program,that program have some tabindex in order to relevant control.then you can use;
SendKeys.Send("{TAB}");
SendKeys.Send("{ENTER}");
it is more accurate on desktop application

Closing frontmost window in Cocoa in an app without a menu bar

I am building a StatusBar App in Cocoa, therefore I have no menu. Having no menu implies not having a "File > Close" menu item, which normally listens to the shortcut "Command + W".
From my StatusBar App the user may open a window to change the preferences and that's where I'm running into problems: The user can only close the window by pressing the red dot with the mouse. However, like alle applications I want to support the "Command + W" shortcut as well.
At the moment I see two possibilities to solve this issue:
Place an invisible button on the window which listens to the shortcut.
Add an application-wide listener for the shortcut and contact the window manually.
Both solutions feel like a misuse of the system. The first solution can lead to unexpected behaviour (the window closes if the user hits the invisible button by chance) and the second solution will still result in a beep, since the window does not know that it handles such a shortcut.
Is there an elegant way to solve this problem? Since the view should know what to do, a solution with just Interface Builder would be perfect. If there is no elegant way, is there a way to enhance the solutions mentioned?
Thanks in advance!
If you put a File > Close menu item in your MainMenu nib, the shortcut will work, even though the menu isn't visible.
If you choose to implement an app-wide listener for the shortcut instead, you can get rid of the beep by returning nil from the block, so that the original event doesn't get passed on.

Binding key combinations to your application

How can I bind a key combination to my vb.net application? I know it has SOMETHING to do with the registry, but I have no earthly idea what or how to go about doing this. I want the user to be able to hit those keys when the app is open and have it execute my function, but not while the app is closed.
Thanks for the help!
If you are using a dialog, then you can put '&' into the text for some controls (buttons, checkboxes, radio buttons, etc) and this will cause Alt plus the next character in the text to be used as an accelerator/shortcut. i.e. "&Open" would activate the Open button if you press Alt+O. "Op&en" would activate if for Alt+e.
Beyond that, as Jason Irwin said, you need to add an event handler to your Form for KeyDown or KeyPress events, and then check if the keypress is the key combination you are interested in. This will only work if the user activates your form (clicks in it to give it the input focus. If they put it behind another window, it will not react to the key presses)
If you don't want to show a form, or want to react to keypresses when you're not the input-focus application, then it gets a bit more complicated (you either need to use a hidden form or a keyboard hook)
edit
OK, it looks like you want a keyboard hook. This looks like a good article.
It depends on what you are trying to do:
If you have a gui application and you want to handle key events then you can do that in a keydown eventhandler
If you want to do more low-level stuff and have an application that will intercept all key strokes (regardless of whether or not the application has focus/is visible) then you need to use pinvoke to hit the win32 apis. I suggest you read the following:
link text
Please let us know what you are trying to do so we can provide better feedback.
Using Google, I found this Keyhook example.
I've worked with keyhooks before, in Delphi WIN32, so I am a bit familiar with them. (Just not in C#.) If you add one to a DLL, all Hell might break loose since most virus scanners will recognise this as malware behaviour. (Especially if you use them in the wrong way, causing them to be injected in each and every process that's running on your system.)
A keyhook will allow key combinations to be captured from other processes, though.
For a solution without programming requirements: Drop a shortcut for the application on your desktop. Edit it, assign a shortcut, close it. Press shortcut to test...