Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

for msac_m

Posted on 1998-11-19
3
134 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:jpenev3
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
ahalya earned 10 total points
ID: 1347330
you use a keyboard buffer (just like an array) and then check for keys that are down.
the following code should get you going, i'd guess.


var buf : TKeyboardState;

begin
GetKeyboardState(Buf);

SpeedButton1.Down := (Buf[vk_Shift]   And 128) <> 0;
SpeedButton2.Down := (Buf[vk_Control] And 128) <> 0;
SpeedButton3.Down := (Buf[vk_Menu]    And 128) <> 0;

SpeedButton4.Down := (Buf[vk_NUMLOCK]    And 128) <> 0;
update;

0
 

Expert Comment

by:msac_m
ID: 1347331
Hi jpenev3,

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


Regards

   
0
 

Expert Comment

by:msac_m
ID: 1347332
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.







0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question