wxEVT_KEY_DOWN problem 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
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

wxEVT_KEY_DOWN problem

Post by mxoliveira73 »

Interesting, a simple code doesn't work. Trying a key down event... problem should be in Panel, but i don't understand what is.. whitout a panel works fine...

Code: Select all

void onKeyDown(wxKeyEvent& event);

Panel->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MyFrame::onKeyDown));

void MyFrame::onKeyDown(wxKeyEvent& event)
{
wxMessageBox("lalala");
}

User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxEVT_KEY_DOWN problem

Post by doublemax »

A panel usually doesn't have keyboard focus. Try calling panel->SetFocus().

In a real-world application it usually doesn't make sense to catch keyboard events from a wxPanel. Depending on what you try to achieve, this might help: https://wiki.wxwidgets.org/Catching_key_events_globally
Use the source, Luke!
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

Re: wxEVT_KEY_DOWN problem

Post by mxoliveira73 »

Oh, I'm ashamed for this question... In true, I explained wrong. I'd like an event for many objects, if I release key "l", button1 set background original color; if I release key "M", button2 set background color original color... etc.. because when I pressed this keys I turned it other hover colors.... using wxEVT_CHAR_HOOK....

Then, would be something like this...

Code: Select all

 void MyFrame::OnKeyDown(wxKeyEvent& event)
{
    wxChar uc = event.GetUnicodeKey();

    switch (uc){
    case 32:   if(){button1->SetBitmap(imageHover1)  } ;break;
    case 33:   if(){button2->SetBitmap(imageHover2)  } ;break;
    case 34:   if(){button3->SetBitmap(imageHover3)  } ;break;
}
}


void MyFrame::OnKeyUp(wxKeyEvent& event)
{
    wxChar uc = event.GetUnicodeKey();

    switch (uc){
    case 76:   if(){button1->SetBitmap(imageOriginal1)  } ;break;
    case 77:   if(){button2->SetBitmap(imageOriginalr2)  } ;break;
    case 78:   if(){button3->SetBitmap(imageOrigianl3)  } ;break;
}
} 
But, I solved creating one event for each button.... and then i clicked one key, set focus on button1, for example, and release the key, the button react on individually function.... then, big thanks, one more time, doublemax.....
Post Reply