Jump to content
Sign in to follow this  
Tommi Prami

Capturing paste at the form level, possibly bypassing components

Recommended Posts

Hello,

I need either VLC / WinMessage / WinAPI solution to this. 

Current (very old) implementation uses Forms KeyPreview set to true. Then  on KeyUp event paste key kombinations will invoke code that will get data from keyboard, and Key is set to zero.

It mostly works, but sometimes edit controls are faster to capture the paste. Would need bit more robust version for this.

-Tee-

Edited by Tommi Prami

Share this post


Link to post

Drop TApplicationEvents component on the form and implement the OnMessage event handler.

 

procedure TMainForm.ApplicationEventsMessage(var Msg: tagMSG; var Handled: boolean);
var Key: Word;
    ShiftState: TShiftState;
    ctrl: TWinControl;
begin
    case Msg.Message of
    WM_KEYDOWN:
    begin
        Key := Msg.wParam;
        ShiftState := KeyDataToShiftState(Msg.lParam);

        if (ssCtrl in ShiftState) and (Key = Ord('V')) then
        begin
            ctrl := FindControl(Msg.hwnd);
            //do whatever you need to do
            Handled := true;
        end;
    end;
    end;
end;

 

Edited by dwrbudr
  • Like 1

Share this post


Link to post
17 minutes ago, dwrbudr said:

Drop TApplicationEvents component on the form and implement the OnMessage event handler.

 


procedure TMainForm.ApplicationEventsMessage(var Msg: tagMSG; var Handled: boolean);
var Key: Word;
    ShiftState: TShiftState;
    ctrl: TWinControl;
begin
    case Msg.Message of
    WM_KEYDOWN:
    begin
        Key := Msg.wParam;
        ShiftState := KeyDataToShiftState(Msg.lParam);

        if (ssCtrl in ShiftState) and (Key = Ord('V')) then
        begin
            ctrl := FindControl(Msg.hwnd);
            //do whatever you need to do
            Handled := true;
        end;
    end;
    end;
end;

 

Nice...
 

ctrl := FindControl(Msg.hwnd); // <- could you tell me what is this for?
Edited by Tommi Prami
Formatting

Share this post


Link to post

If you want to do specific actions based on the VCL control that was about to receive the message, like a TTreeView, TEdit, etc.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×