Friends who have used programming languages such as Visual Basic must be very familiar with their SendKeys functions. You can use this function to send a string to a target window (such as Notepad) or a control (such as an edit control), as if you were entering the string in the target window or control.
However, the Delphi does not provide us with such a function. In fact, Borland engineers have long provided a convenient way: in the Delphi5.0 Enterprise version of the installation disk \info\extras\sendkeys\ folder, there is a Sndkey32.pas file,
Simply copy the file to the Delphi installation directory under the \lib\ folder and use the SendKeys function after referencing the file in the project.
The two main functions are:
SendKeys (Keystring:pchar; Wait:boolean): Boolean;
AppActivate (Windowname:pchar): Boolean;
Usage is:
The SendKeys function sends a string to the window or control that currently has focus, keysering the contents of the string.
Wait indicates whether the window or control waiting to receive the string is finished processing and returned. Generally set to false.
For example: SendKeys (' ABCDEFG ', false);
It is worth mentioning that the SendKeys function supports sending special characters and combination characters, such as arrow keys, ALT, and CTRL key combinations.
When used, just use the specified prefix. + for shift,^ to ctrl,% for Alt.
For example:
' +monday ' means to send shift+m and Onday
' + (Monday) ' means to send Shift+monday
for invisible characters (such as arrow keys, F1~F11, carriage returns, and so on), you can enclose them in {}.
For example:
The '%{f4} ' is a combination of sending alt+f4 to the application.
For more detailed instructions, refer to the comments in the Sndkey32.pas file.
The role of the AppActivate function is to set a window as the current window. Simply pass the title of the window to the past.
If a window is successfully activated, the return value is true.
Example: After you click Send, the contents of the edit control above will be sent to the following edit control.
The program is simple, with just two edit controls and a button control.