Page 1 of 1
Intercepting keystrokes while in richtext edit control
Posted: Wed Jan 03, 2007 6:24 am
by reinaldocrespo
Hi.
I'm needing to process certain function keys while editing inside a richtext edit control. My code looks something like this:
Code: Select all
::oRtf:bKeyDown := {| nKey | ::ProcessMacroKeys( nKey ) }
...
//----------------------------------------------
METHOD ProcessMacroKeys( nKey ) CLASS PATHTRANS
Local cMacro := Spac( 9 )
logfile( "trace.log", { nKey } )
....
Nothing logs. The ProcessMacroKey method never gets called. What am I missing here?
Reinaldo.
Re: Intercepting keystrokes while in richtext edit control
Posted: Wed Jan 03, 2007 10:23 am
by Enrico Maria Giordano
Try with
Code: Select all
::oRtf:bKeyChar := {| nKey | ::ProcessMacroKeys( nKey ) }
EMG
Posted: Wed Jan 03, 2007 5:04 pm
by reinaldocrespo
Enrico;
Hi. Good to read your response.
I tried it, but still nothing happens. It might be due to the fact that the rtfs are housed inside a tab control. I even tried with and without ::oRtf:nDlgCode = DLGC_WANTALLKEYS at no avail.
Any other suggestion is very much welcomed.
Reinaldo.
Posted: Wed Jan 03, 2007 5:13 pm
by James Bott
Reinaldo,
Both bKeyDown and bKeyChar are not called until all other special keys have been processed (TRichEdit calls TControl calls TWindow for both methods). So if you are trying to trap a key that is being used in any of those methods it will never get processed. You can try trapping just a letter key to see if that works. If so, then this is your problem.
The only solution would be to either use a different key, or subclass TRichEdit and override the keyDown or KeyChar method to trap the keys you want.
James
Posted: Wed Jan 03, 2007 5:18 pm
by Enrico Maria Giordano
reinaldocrespo wrote:Enrico;
Hi. Good to read your response.
I tried it, but still nothing happens. It might be due to the fact that the rtfs are housed inside a tab control. I even tried with and without ::oRtf:nDlgCode = DLGC_WANTALLKEYS at no avail.
Any other suggestion is very much welcomed.
Reinaldo.
This is a working sample (without tab control):
Code: Select all
#include "Fivewin.ch"
#include "Richedit.ch"
FUNCTION MAIN()
LOCAL hDll := LOADLIBRARY( "RICHED20.DLL" )
LOCAL oWnd, oRtf
LOCAL cVar := ""
DEFINE WINDOW oWnd
@ 0, 0 RICHEDIT oRtf VAR cVar
oRtf:bKeyChar = { | nKey | MsgInfo( nKey ) }
oWnd:oClient = oRtf
ACTIVATE WINDOW oWnd
FREELIBRARY( hDll )
RETURN NIL
EMG
Posted: Wed Jan 03, 2007 5:39 pm
by reinaldocrespo
James;
Thank you for the reply.
I had already tried that. However, I'm not able to capture any function key F1 - F12.
Here is the code I'm using:
Code: Select all
METHOD KeyDown( nKey, nFlags ) CLASS RchEdt
logfile( "trace.log", { nKey } )
Super:KeyDown( nKey, nFlags )
RETURN Nil
*-------------------------------------------------------------------------------------------------------------------------------
METHOD KeyChar( nKey, nFlags ) CLASS RchEdt
logfile( "trace.log", { nKey } )
super:Keydown( nKey, nflags )
return nil
Only ascii codes for normal keys 0-9, a-z, and A-Z gets logged. Therefore I assume that Function keys are not being handled by keychar nor keydown.
Reinaldo
Posted: Wed Jan 03, 2007 5:59 pm
by James Bott
Reinaldo,
This works for me capturing function keys (except for F1 and F10 which are reserved by Windows) with the standard richedit class. [Note that function keys are trapped in the KeyDown() method.] So perhaps it does have something to do with the tab control. Can you provide a small self-contained example?
James
Code: Select all
#include "Fivewin.ch"
#include "Richedit.ch"
FUNCTION MAIN()
LOCAL hDll := LOADLIBRARY( "RICHED20.DLL" )
LOCAL oWnd, oRtf
LOCAL cVar := ""
DEFINE WINDOW oWnd
@ 0, 0 RICHEDIT oRtf VAR cVar
oRtf:bKeyDown = { | nKey | Msginfo(nKey) }
oWnd:oClient = oRtf
ACTIVATE WINDOW oWnd
FREELIBRARY( hDll )
RETURN NIL