User forums > General (but related to Code::Blocks)
wxScintilla events
(1/1)
killerbot:
I have been looking at the wxScintilla reference, but I did not quit find what I was looking for.
I'd like to be notified (through wxScintillaEvent) every time a key is pressed. Event type wxEVT_SCI_KEY is no option, since that one is not sended on windows :-(
Another thing I could do is EVT_CHAR_HOOK, but how do I know then that the keypresses are coming from the active editor and not a key pressed in some other control or menu.
Next to this I need to know when the user left clicked somewhere in the editor.
Any ideas.
sethjackson:
EVT_KEY_DOWN doesn't work or maybe the wxScintilla control doesn't send this event???
killerbot:
probably same problem : how do I know the EVT_KEY_DOWN comes from the editor and not from another control in CB (or menu) ?
eranif:
Hi,
If scintilla does not fire the event, you can workaround it by providing your own event handler and process them before scintilla
do, you just derive a class from wxEvtHandler and add it to the window event handlers.
Here is a simple code that should do what you need (in the following example, I tried to intercept KEY_DOWN, CHAR, CHAR_HOOK, KEY_UP
events):
--- Code: ---class MyEvtHandler : public wxEvtHandler
{
public:
void SetWindow(wxWindow *win) { m_win = win; }
MyEvtHandler(wxESFlatMenu *menu, wxEvtHandler* oldHandler)
: m_oldHandler( oldHandler )
{ SetWindow(win); };
virtual bool ProcessEvent(wxEvent& event)
{
if ( event.GetEventType() == wxEVT_KEY_DOWN || event.GetEventType() == wxEVT_KEY_UP ||
event.GetEventType() == wxEVT_CHAR || event.GetEventType() == wxEVT_CHAR_HOOK)
{
// Process the event here (assuming you derived class is called Editor)
Editor* editor = dynamic_cast<Editor*>(m_win);
if( editor )
{
editor->ProcessKeyDown((wxKeyEvent &)event);
}
// And let scintilla keep processing the event
return m_oldHandler->ProcessEvent(event);
}
}
private:
wxWindow *m_win;
wxEvtHandler* m_oldHandler;
};
// in your code, replace the old handler with MyEvtHandler
// Somewhere in the construction of the control put this line:
PushEventHandler(new MyEvtHandler(this, GetEventHandler()) );
// And in the destructor of the control - or in its OnClose function or something similar, add:
PopEventHandler( true ); // Delete the new handler and use the previous one
--- End code ---
Hope that helped,
Eran
Pecan:
--- Quote from: killerbot on August 26, 2006, 11:09:10 pm ---probably same problem : how do I know the EVT_KEY_DOWN comes from the editor and not from another control in CB (or menu) ?
--- End quote ---
You can also use connect/disconnect events.
Look at cbDragScroll. You might even be able to use/copy the code, but use a key event instead of a mouse event.
Navigation
[0] Message Index
Go to full version