FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Intercepting keystrokes while in richtext edit control
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Intercepting keystrokes while in richtext edit control
Posted: Wed Jan 03, 2007 06:24 AM
Hi.

I'm needing to process certain function keys while editing inside a richtext edit control. My code looks something like this:

::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.
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Intercepting keystrokes while in richtext edit control
Posted: Wed Jan 03, 2007 10:23 AM
Try with

::oRtf:bKeyChar := {| nKey | ::ProcessMacroKeys( nKey ) }


EMG
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Intercepting keystrokes while in richtext edit control
Posted: Wed Jan 03, 2007 05: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.

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Intercepting keystrokes while in richtext edit control
Posted: Wed Jan 03, 2007 05: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Intercepting keystrokes while in richtext edit control
Posted: Wed Jan 03, 2007 05: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 ::nDlgCode = DLGC_WANTALLKEYS at no avail.

Any other suggestion is very much welcomed.


Reinaldo.


This is a working sample (without tab control):

#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
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Intercepting keystrokes while in richtext edit control
Posted: Wed Jan 03, 2007 05: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:

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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Intercepting keystrokes while in richtext edit control
Posted: Wed Jan 03, 2007 05: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

#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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion