Board index » cppbuilder » Trapping a key press

Trapping a key press


2007-01-23 11:31:22 PM
cppbuilder64
Hi,
I am using a TStringGrid on a form. When the user selects
Control c or Control v, I want to trap this and use my own code
instead of the standard copy and paste to/from clipboard.
I have read some of the previous posts and have tried setting
Key=0 in the OnKeyDown event handler for the stringgrid and
executing my own code. This does not seem to work and the
standard function for Control c or v is being called after my
code executes.
I have also tried using the OnKeyUp event handler with no
success. I have tried the TForm::OnKeyDown event handler and
it does not appear to be called.
Any help is appreciated.
Thanks.
 
 

Re:Trapping a key press

"JB" < XXXX@XXXXX.COM >wrote in message
Quote
...
Hi,
I have read some of the previous posts and have tried setting
Key=0 in the OnKeyDown event handler for the stringgrid and
executing my own code. This does not seem to work and the
standard function for Control c or v is being called after my
code executes.
I have also tried using the OnKeyUp event handler with no
success. I have tried the TForm::OnKeyDown event handler and
it does not appear to be called.
You're trying to set up your traps in the wrong woods.
It is the InplaceEditor property that sits on the top
of a grid cell and handles all the keyboard input.
Try to catch/subclass the beast and process WM_COPY,
WM_CUT, WM_PASTE etc. messages the way you want. Just
keep in mind that "The inplace editor is created the
first time the grid is put in edit mode." Boba.
 

Re:Trapping a key press

"Boba" < XXXX@XXXXX.COM >wrote:
Quote
It is the InplaceEditor property that sits on the top
of a grid cell and handles all the keyboard input.
Try to catch/subclass the beast and process WM_COPY,
WM_CUT, WM_PASTE etc. messages the way you want.
Thanks, I now know where the messages are going.
I have actually subclassed the TStringGrid to override the
CreateEditor method to allow me to access it's functions.
Do I now need to subclass the TInplaceEditor to get at the
KeyDown event handler? If so can you give me a pointer on how
to achieve this?
Many Thanks,
JB
 

{smallsort}

Re:Trapping a key press

"JB" < XXXX@XXXXX.COM >wrote in message
Quote
... If so can you give me a pointer on how
to achieve this?
TCustomGrid::InplaceEditor is a TWinControl descendant. as such it has
HWND Handle to access its window. subclass it as you would any other window.
 

Re:Trapping a key press

"Boba" < XXXX@XXXXX.COM >wrote:
Quote
TCustomGrid::InplaceEditor is a TWinControl descendant. as such it has
HWND Handle to access its window. subclass it as you would any other window.

Thanks, have managed to get it sorted.