Home
Top.Mail.Ru Yandeks.Metrika
Forum: "Main";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Down

How to send a message to the system that a key is pressed? Find similar branches


Delphimun   (2001-12-20 12:10) [0]

How to send a message to the system that a key is pressed? For example, you put on a timer this message to the system that the key is pressed, and the user is currently working in notepad and that these letters are written in the notebook, which you sent to the system



gek   (2001-12-20 12:32) [1]

You get a notepad handle and send it to wm_keydown



Delphimun   (2001-12-20 13:10) [2]

I have already figured it out (I needed not only to send the notebook, but the general system)
Here is an example from faq who is interested:

-------------------------------------------------- -----------------------
Below is the procedure for sending clicks to any
a control (window control) that can accept input from
keyboard. You can use this technique to turn on the keys.
NumLock, CapsLock and ScrollLock under Windows NT. The same technique works
and under Windows 95 for CapsLock and ScrollLock but does not work for the key
NumLock.
Please note that there are four procedures: SimulateKeyDown () -
emulate keystrokes (without releasing) SimulateKeyUp () -
emulate key release SimulateKeystroke () - emulate a hit
on the key (press and release) and SendKeys (), allowing you to flexibly
control keyboard messages sent.
SimulateKeyDown (), SimulateKeyUp () and SimulateKeystroke () receive codes
virtual keys (virtural key) (like VK_F1). Procedure
SimulateKeystroke () gets an extra parameter, useful when
emulate clicking printscreen. When this parameter is zero all
The screen will be copied to the clipboard. If extra
the parameter is equal to 1 only the active window will be copied.
Four methods of "button click" demonstrate usage:
ButtonClick1 - includes capslock ButtonClick2 - intercepts all
screen to clipboard (clipboard). ButtonClick3 - intercepts
active window to the clipboard (clipboard). ButtonClick4 - sets the focus to Edit and
sends a string to it.
Example:

procedure SimulateKeyDown (Key: byte);
begin
keybd_event (Key, 0, 0, 0);
end;

procedure SimulateKeyUp (Key: byte);
begin
keybd_event (Key, 0, KEYEVENTF_KEYUP, 0);
end;

procedure SimulateKeystroke (Key: byte; extra: DWORD);
begin
keybd_event (Key, extra, 0,0);
keybd_event (Key, extra, KEYEVENTF_KEYUP, 0);
end;

procedure SendKeys (s: string);
var i: integer;
flag: bool;
w: word;
begin
{Get the state of the caps lock key}
flag: = not GetKeyState (VK_CAPITAL) and 1 = 0;
{If it becomes a caps lock
if flag then
SimulateKeystroke (VK_CAPITAL, 0);
for i: = 1 to Length (s) do
begin
w: = VkKeyScan (s [i]);
{If there is no error in the key translation}
if ((HiByte (w) <> $ FF) and (LoByte (w) <> $ FF)) then
begin
{If the key requires the shift key down - hold it down}
if HiByte (w) and 1 = 1 then
SimulateKeyDown (VK_SHIFT);
{Send the VK_KEY}
SimulateKeystroke (LoByte (w), 0);
{If the key required the shift key down - release it}
if HiByte (w) and 1 = 1 then
SimulateKeyUp (VK_SHIFT);
end;
end;
{if it was a caps lock
if flag then
SimulateKeystroke (VK_CAPITAL, 0);
end;

procedure TForm1.Button1Click (Sender: TObject);
begin
{Toggle the cap lock}
SimulateKeystroke (VK_CAPITAL, 0);
end;

procedure TForm1.Button2Click (Sender: TObject);
begin
{Capture the screen}
{by simulating pressing the print screen key}
SimulateKeystroke (VK_SNAPSHOT, 0);
end;

procedure TForm1.Button3Click (Sender: TObject);
begin
{Capture the window to the clipboard}
{by simulating pressing the print screen key}
SimulateKeystroke (VK_SNAPSHOT, 1);
end;

procedure TForm1.Button4Click (Sender: TObject);
begin
{Set the focus to a window (edit control) and send it a string}
Application.ProcessMessages;
Edit1.SetFocus;
SendKeys ("Delphi Is RAD!");
end;
---------------------------------------------------------------------------

Now I need to track the user's click on the Claudia button (for example, the alfit one) and nullify this click \ replace it with my own.




Pages: 1 whole branch

Forum: "Main";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Top









Memory: 0.57 MB
Time: 0.032 c
3-21942
Rev
2001-12-03 12:19
2002.01.08
Good people help with the stored procedure.


3-21945
asafr
2001-12-04 18:11
2002.01.08
FastReport. frBand.Visible


1-22051
kay
2001-12-18 22:22
2002.01.08
Richedit


4-22508
Gluka
2001-11-06 00:18
2002.01.08
Is it possible to change the cursor over someone else's window?


3-21994
Vs
2001-12-06 16:23
2002.01.08
Dynamic array





afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic indonesian Irish italian Japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Español swahili Swedish thai turkish Ukrainian urdu vietnamese welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
zulu
English French German Italian Portuguese Russian Spanish