Intercepting keystrokes while in richtext edit control

Post Reply
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Intercepting keystrokes while in richtext edit control

Post 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.
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Post 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.
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post 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
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
Post Reply