Intercepting keystrokes while in richtext edit control

Intercepting keystrokes while in richtext edit control

Postby reinaldocrespo » Wed Jan 03, 2007 6:24 am

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  Expand view
::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: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Intercepting keystrokes while in richtext edit control

Postby Enrico Maria Giordano » Wed Jan 03, 2007 10:23 am

Try with

Code: Select all  Expand view
::oRtf:bKeyChar := {| nKey | ::ProcessMacroKeys( nKey ) }


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8696
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby reinaldocrespo » Wed Jan 03, 2007 5:04 pm

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

Postby James Bott » Wed Jan 03, 2007 5:13 pm

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

Postby Enrico Maria Giordano » Wed Jan 03, 2007 5:18 pm

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  Expand view
#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
Enrico Maria Giordano
 
Posts: 8696
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby reinaldocrespo » Wed Jan 03, 2007 5:39 pm

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  Expand view
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
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Postby James Bott » Wed Jan 03, 2007 5:59 pm

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 24 guests