keyboard event Topic is solved

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
jkbagain
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 09, 2007 1:01 am
Location: Manila,Philippines
Contact:

keyboard event

Post by jkbagain » Thu May 10, 2007 6:31 am

Does anyone here knows on how to make the cursor of a wxTextField to transfer to another wxTextField by pressing the tab on the keyboard....

Example,,,suppose you have two txtFields in the frame and the cursor of the mouse is in one of the txtfield and byy pressing the tab of your keyboard the cursor will transfer on the second text field....


I hope you have the idea about this one............
Thanks in advanced...
What important in a problem is not the solution but the lessons you learned in finding the solution.

megabyte
I live to help wx-kind
I live to help wx-kind
Posts: 196
Joined: Tue Dec 07, 2004 8:54 pm
Location: Essen, Germany

Post by megabyte » Thu May 10, 2007 6:49 am

Define a custom EVT_SET_FOCUS event handler for all you text controls. In the event handler call

Code: Select all

WarpPointer(wxPoint(0, 0));
It will point the mouse cursor to the top-left corner of the control.

jkbagain
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 09, 2007 1:01 am
Location: Manila,Philippines
Contact:

Post by jkbagain » Thu May 10, 2007 7:03 am

thank you megabyte for your response about my question in the forum about the the text ctrl but I am still confuse....
Could you pls help me on how to define these event for i dont have an idea about this one or provide me a simple program about this one.....
I hope you could help me this one.......if u r bc its,alright,, i can wait for your reply
What important in a problem is not the solution but the lessons you learned in finding the solution.

megabyte
I live to help wx-kind
I live to help wx-kind
Posts: 196
Joined: Tue Dec 07, 2004 8:54 pm
Location: Essen, Germany

Post by megabyte » Thu May 10, 2007 7:18 am

Not a problem. Code snippet is

Code: Select all

class MyTextCtrl : public wxTextCtrl
{
public:
    MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value,
               const wxPoint &pos, const wxSize &size, int style = 0)
        : wxTextCtrl(parent, id, value, pos, size, style)
    {
    }
    void OnSetFocus(wxFocusEvent& event);
private:
    DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
    EVT_SET_FOCUS(MyTextCtrl::OnSetFocus)
END_EVENT_TABLE()

void MyTextCtrl::OnSetFocus(wxFocusEvent& event)
{
    WarpPointer(wxPoint(0, 0));
    event.Skip();
}
and the control usage is the same as wxTextCtrl, i.e.

Code: Select all

MyTextCtrl *pMyText = new MyTextCtrl( this, wxID_ANY, _T(""), wxPoint(10,50), wxSize(140,wxDefaultCoord));

clyde729
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Mon May 29, 2006 10:50 pm
Location: Jena, Germany

Post by clyde729 » Thu May 10, 2007 7:44 am

Do you want to move the mouse-cursor by program or do you want to move the keyboard-cursor (the blinking " | " ) ? The latter should work automatically, if you create "textfield_1" before "textfield_2" and put them both on panels.

Try to run some sample-apps from wxWidgets (i.e. the text-sample) to get an idea on how it works.
OS: Windows XP Home, Compiler: MingW, Version: wxWidgets 2.8.0, IDE: wx-Devcpp

jkbagain
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 09, 2007 1:01 am
Location: Manila,Philippines
Contact:

thanks for the response

Post by jkbagain » Thu May 10, 2007 8:29 am

Thnkz clyde for your effort to help.....What i wanted is to move the keyboard cursor on the nxt textfield by pressing the keyboard tab so that i could write on the next txtfield...
As you have said that this must work automatically if the txtfield1 before txtfield2 but on my program it doesnt work....My txtfields in not on the panel but on the same frame...I hope you could help me with this one

Thanks......
What important in a problem is not the solution but the lessons you learned in finding the solution.

megabyte
I live to help wx-kind
I live to help wx-kind
Posts: 196
Joined: Tue Dec 07, 2004 8:54 pm
Location: Essen, Germany

Post by megabyte » Thu May 10, 2007 8:48 am

I thought about a mouse cursor. So my code does not solve your problem. As it was mentioned before, the text cursor should appear automatically in every text control after it become focused.

There are not so much details, to decide what is the problem reason. Can you post your code which creates the text controls.

jkbagain
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 09, 2007 1:01 am
Location: Manila,Philippines
Contact:

thanks for concern and here is my code

Post by jkbagain » Thu May 10, 2007 9:10 am

Thanks ,,,megabyte for your help,,,I really appreciate your concern...Thank you very much.....Thanks

Here is my code ::::
Attachments
txtctrl.cpp
what i wanted is that if the cursor is on the first txtfield and if u enter the tab key of the keyboard the txtcursor will move to the nxt txt field......Thanks a lot for your help
(758 Bytes) Downloaded 35 times
What important in a problem is not the solution but the lessons you learned in finding the solution.

jkbagain
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 09, 2007 1:01 am
Location: Manila,Philippines
Contact:

thanks for concern and here is my code

Post by jkbagain » Thu May 10, 2007 9:15 am

Thanks ,,,megabyte for your help,,,I really appreciate your concern...Thank you very much.....Thanks

Here is my code ::::
Attachments
txtctrl.cpp
what i wanted is that if the cursor is on the first txtfield and if u enter the tab key of the keyboard the txtcursor will move to the nxt txt field......Thanks a lot for your help
(758 Bytes) Downloaded 28 times
What important in a problem is not the solution but the lessons you learned in finding the solution.

jkbagain
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 09, 2007 1:01 am
Location: Manila,Philippines
Contact:

here is my code and thanks

Post by jkbagain » Thu May 10, 2007 9:16 am

Thanks ,,,megabyte for your help,,,I really appreciate your concern...Thank you very much.....Thanks

Here is my code ::::


#include "wx/wx.h"

class MyApp: public wxApp{
virtual bool OnInit();
};

class MyFrame: public wxFrame{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,long style);
};

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit(){
MyFrame *frame = new MyFrame( _T("PhoneToPhone"), wxPoint(310,200), wxSize(425,319),wxSYSTEM_MENU|wxCLOSE_BOX);
frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,long style)
: wxFrame((wxFrame *)NULL, -1, title, pos, size,style){
wxTextCtrl *txtctrl=new wxTextCtrl(this,-1,_T(""),wxPoint(140,25),wxSize(130,25));
wxTextCtrl *txtctrl_1=new wxTextCtrl(this,-1,_T(""),wxPoint(140,130),wxSize(130,25));
}


What i wanted is that if the cursor is on the first txtfield and if u enter the tab key of the keyboard the txtcursor will go to the nxt txtfield so that u can write on it..

Thanks for your hellp...I really appreciate your hellp....Thank you...
What important in a problem is not the solution but the lessons you learned in finding the solution.

megabyte
I live to help wx-kind
I live to help wx-kind
Posts: 196
Joined: Tue Dec 07, 2004 8:54 pm
Location: Essen, Germany

Post by megabyte » Thu May 10, 2007 9:46 am

I compiled you code. I have two borderless text controls in a frame without any caption and border, the controls have text cursors if to focus them using mouse, but the Tab does not work due to the wxTAB_TRAVERSAL flag missing. So I changed the frame creation line

Code: Select all

 MyFrame *frame = new MyFrame( _T("PhoneToPhone"), wxPoint(310,200), wxSize(425,319),wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL);
After this the frame controls are tab traversal. Unfortunately I cannot to reproduce your problem with missing text cursors.

jkbagain
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 09, 2007 1:01 am
Location: Manila,Philippines
Contact:

thanks,,megabyte

Post by jkbagain » Fri May 11, 2007 12:54 am

Thankz for your effort to help me...thank you..
What important in a problem is not the solution but the lessons you learned in finding the solution.

JSThePatriot
Earned some good credits
Earned some good credits
Posts: 146
Joined: Sun Nov 26, 2006 7:37 am
Location: Tennessee, USA
Contact:

Post by JSThePatriot » Fri May 11, 2007 5:23 pm

megabyte wrote:I compiled you code. I have two borderless text controls in a frame without any caption and border, the controls have text cursors if to focus them using mouse, but the Tab does not work due to the wxTAB_TRAVERSAL flag missing. So I changed the frame creation line

Code: Select all

 MyFrame *frame = new MyFrame( _T("PhoneToPhone"), wxPoint(310,200), wxSize(425,319),wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL);
After this the frame controls are tab traversal. Unfortunately I cannot to reproduce your problem with missing text cursors.
I dont think he had a problem of missing text cursors. I think he only wanted the wxTAB_TRAVERSAL, as was stated in his first post when he mentioned the need to use "TAB" to go between controls. However if he is missing the actual cursor then it is a problem in the software of not letting the OS know what type of control it is in, and handling that properly.

JS
OS Windows XP Pro
Compiler MinGW 3.4.5
wxWidgets 2.8.7 (Unicode : Monolithic : Release)
IDE Code::Blocks (Latest Release)
RAD wxFormBuilder (Latest Release)

jkbagain
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 09, 2007 1:01 am
Location: Manila,Philippines
Contact:

thnksz

Post by jkbagain » Tue May 15, 2007 1:10 am

thanks for your response and i think you got the right point coz currently i am using the ubuntu flavor of linux and the TAB_TRANSVERSAL doesn't work in linux but in win32 it works,,,so i think it is in the OS...
What important in a problem is not the solution but the lessons you learned in finding the solution.

Post Reply