AlexeiScherbakov / osklib

Library for controlling Windows On Screen Keyboard
MIT License
43 stars 13 forks source link

Is a KeyboardClosed event possible? #3

Closed jb455 closed 6 years ago

jb455 commented 6 years ago

Hi, When I call the keyboard to open I have to move some UI around so the user can see what they're typing, then when the user taps off the field I close the keyboard and move the UI back. However, if the user closes the keyboard manually by pressing the x on it, the UI doesn't know it has to move back. Would it be possible to make a KeyboardClosed event I can subscribe to to move the UI back when the keyboard is closed manually?

Thanks!

AlexeiScherbakov commented 6 years ago

Yes, it is possible. I added 'OnScreenKeyboardWatcher' class which implements KeyboardOpened & KeyboardClosed events.

jb455 commented 6 years ago

That's perfect, thanks so much! For future reference, the events occur on a separate thread without access to UI so if you want to change UI stuff within the events, it needs to be invoked like so:

private void Watcher_KeyboardClosed(object sender, EventArgs e)
{
    Dispatcher.Invoke((Action)(() =>
    {
        //Change UI stuff
    }));
}
AlexeiScherbakov commented 6 years ago

In version 1.3 DispatcherOnScreenKeyboardWatcher and WinFormsKeyboardWatcher classes implement same logic without needing invoke call