On-Screen keyboard

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
zverj
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Feb 07, 2008 4:11 pm

On-Screen keyboard

Post by zverj » Tue Jul 15, 2008 12:55 pm

Hello

I want to implement on-screen keyboard like functionality for my application.

1) How can I determine which control has focus? (if I press button, doesn't the button get focus?)
2) How can I simulate keypress ?

Thank you in advance

chris_bern
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Mar 05, 2008 3:30 pm

Post by chris_bern » Tue Jul 15, 2008 1:40 pm

Hi,

I think this class may help you

Code: Select all

wxAcceleratorTable
Chris

zverj
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Feb 07, 2008 4:11 pm

Post by zverj » Tue Jul 15, 2008 3:48 pm

chris_bern wrote:Hi,

I think this class may help you

Code: Select all

wxAcceleratorTable
And how does this relate to simulating a keypress?

arkief
Knows some wx things
Knows some wx things
Posts: 41
Joined: Tue Jan 15, 2008 9:13 am

Post by arkief » Tue Jul 15, 2008 5:25 pm

Hi,
Maybe not the best idea, but one (I hope it works):

Code: Select all

//*.h-file

class a : public wxWindow       //keyboard-class
{
private:
    wxWindow *lastFocus;
    DECLARE_EVENT_TABLE()
    void gotFocus(wxFocusEvent &event)
    {
        lastFocus = event.GetWindow();
    }
    
    void buttonClicked(wxButtonEvent &event)
    {
        lastFocus->SetFocus();
        wxKeyEvent keyEvent(65);  //keycodes-table: http://docs.wxwidgets.org/stable/wx_keycodes.html#keycodes
        keyEvent.SetEventObject(this);
        keyEvent.SetId(lastFocus->GetId());
        lastFocus->GetEventHandler()->ProcessEvent(keyEvent); 
    }
};

//*.cpp-file
#include ".h"

BEGIN_EVENT_TABLE(a, wxWindow)
    EVT_SET_FOCUS(a::gotFocus)
    EVT_BUTTON(wxID_ANY, a::buttonClicked)
END_EVENT_TABLE()
I hope it helps!

Regards

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Tue Jul 15, 2008 11:55 pm

You can find which one has the focus with :
http://docs.wxwidgets.org/stable/wx_wxw ... wfindfocus

chris_bern
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Mar 05, 2008 3:30 pm

Post by chris_bern » Wed Jul 16, 2008 8:48 pm

If your idea is to simulate a key press like some kind of keyboard animation you can use wxToggleButton.

If your idea is to create key shortcuts for series of key presses I think all you need is to catch the key events - wxKeyEvent and then direct some input to particular control.

Chris

zverj
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Feb 07, 2008 4:11 pm

Post by zverj » Thu Jul 17, 2008 7:04 am

chris_bern wrote:If your idea is to simulate a key press like some kind of keyboard animation you can use wxToggleButton.

If your idea is to create key shortcuts for series of key presses I think all you need is to catch the key events - wxKeyEvent and then direct some input to particular control.

Chris
My idea is to provide on-screen keyboard for computer without keyboard, so user can press buttons with mouse.

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Fri Jul 18, 2008 12:19 am

My idea is to provide on-screen keyboard for computer without keyboard, so user can press buttons with mouse.
Is it for...
A) only your app?
B) the whole computer?

If B) : This sounds like a very OS-specific task, I highly doubt you can tackle that with a cross-platform high-level lib like wxWidgets.

chris_bern
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Mar 05, 2008 3:30 pm

Post by chris_bern » Fri Jul 18, 2008 8:32 am

zverj wrote:My idea is to provide on-screen keyboard for computer without keyboard, so user can press buttons with mouse.
I guess the onscreen keyboard should act as a real keyboard for all applications running. If you need this only for Windows you can use http://www.autohotkey.com - an open-source windows app maker with focus on the keyboard shortcuts but also with a lots of functions to create GUI controls.

Here is a script for an on-screen keyboard application http://www.autohotkey.com/docs/scripts/ ... Screen.htm . You can modify it accordingly to apply keystrokes which is very easy with autohotkey. The thing is that you do not need c++ compiler or anything, just install autohotkey, save the script in .ahk file and right click on the file to make windows executable application. Then place it in the startup folder and there will be no need of keyboard.

Chris

Post Reply