Delphi send button

Source: Internet
Author: User

Const
Extendedvkeys: Set of byte =
[Vk_up, vk_down, vk_left, vk_right, vk_home, vk_end, vk_prior, {PG up} vk_next, {pgdn} vk_insert, vk_delete];
/// // Send the button
Procedure sendcardno (cardno: string );
VaR
I: integer;
Begin
For I: = 1 to length (cardno) Do
Begin
Sendkeydown (vkkeyscan (cardno [I]), 1, false );
End;

End;
Procedure sendkeysback (key: Char );
Begin

Sendkeydown (vkkeyscan (key), 1, false );

End;

Procedure sendkeydown (vkey: byte; numtimes: word; genupmsg: Boolean );
VaR
CNT: word;
Scancode: byte;
Numstate: Boolean;
Keyboardstate: tkeyboardstate;
Begin
If (vkey = vk_numlock) then
Begin
Numstate: = bytebool (getkeystate (vk_numlock) and 1 );
Getkeyboardstate (keyboardstate );
If numstate then
Keyboardstate [vk_numlock]: = (keyboardstate [vk_numlock] and not 1)
Else
Keyboardstate [vk_numlock]: = (keyboardstate [vk_numlock] or 1 );
Setkeyboardstate (keyboardstate );
Exit;
End;
Scancode: = Lo (mapvirtualkey (vkey, 0 ));
For CNT: = 1 to numtimes do
If (vkey in extendedvkeys) then
Begin
Keyboardevent (vkey, scancode, keyeventf_extendedkey );
If (genupmsg) then
Keyboardevent (vkey, scancode, keyeventf_extendedkey or keyeventf_keyup)
End
Else
Begin
Keyboardevent (vkey, scancode, 0 );
If (genupmsg) then
Keyboardevent (vkey, scancode, keyeventf_keyup );
End;
End;
Procedure keyboardevent (vkey, scancode: byte; flags: longint );
VaR
Keyboardmsg: tmsg;
Wait: Boolean;
Begin
Wait: = true;
Keybd_event (vkey, scancode, flags, 0 );
If (wait) Then while (
Peekmessage (keyboardmsg, 0, wm_keyfirst, wm_keylast, pm_remove) do
Begin
Translatemessage (keyboardmsg );
Dispatchmessage (keyboardmsg );
End;
End;
Procedure setcardlength (value: integer );
Begin
Cardlength: = value;
End;

Procedure setsendkey (value: Boolean );
Begin
SendKey: = value;
End;

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/lostcity1/archive/2006/03/23/636077.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.