Link to home
Start Free TrialLog in
Avatar of jpenev3
jpenev3

asked on

for msac_m

Do you know the right parameter for keybd_event function
because i don't understand how to simulate pressing
two keys(for example ctrl and C) simultaneously.
Virtual codes include only one key.
                                            Thanks
ASKER CERTIFIED SOLUTION
Avatar of ahalya
ahalya
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of msac_m
msac_m

Hi jpenev3,

 I saw your question today ,
I will write some code and send to you.


Regards

   
Hi  jpenev3,
This is My Unit,


// Unit Begins Here

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
Var
      dwFlags: DWORD;
begin
//     if(isUpDownSt=1) then //KEYUP
//        dwFlags:= dwFlags or KEYEVENTF_KEYUP;
     Memo1.SetFocus;
     dwFlags:= 0;
     keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), dwFlags, 0);
     keybd_event(ord('C'), MapVirtualKey(ord('C'), 0), dwFlags, 0);
     dwFlags:= KEYEVENTF_KEYUP;
     keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), dwFlags, 0);
     keybd_event(ord('C'), MapVirtualKey(ord('C'), 0), dwFlags, 0);
     Application.ProcessMessages;
end;


procedure TForm1.Button2Click(Sender: TObject);
Var
      dwFlags: DWORD;
begin

     Memo1.SetFocus;
     Memo1.Lines.Add('NewLine');
     dwFlags:= 0;
     keybd_event(VK_CONTROL,      MapVirtualKey(VK_CONTROL, 0), dwFlags, 0);
     keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), dwFlags, 0);
     dwFlags:= KEYEVENTF_KEYUP;
     keybd_event(VK_CONTROL,      MapVirtualKey(VK_CONTROL, 0), dwFlags, 0);
     keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), dwFlags, 0);
     Application.ProcessMessages;
end;

end.
// END OF THE UNIT.


1- Open a new application put two buttons,
2- Drag a Memo on the form.
3- Assign the button click events.
4-Run The Application
5- Write Something into the memo and select your writings.
6- press button1 to copy the selected,
7-Press button2 to paste them into the memo.


I hope, it is what you want.

Regards.