从一个序列号自动输入程序里找到的好东西.
procedure
MySendKeys(Keys: PChar);
procedure
SendKeyDown(VKey: Byte);
var
ScanCode: Byte;
begin
ScanCode :
=
Lo(MapVirtualKey(VKey,
0
));
keybd_event(VKey, ScanCode,
0
,
0
);
end
;
procedure
SendKeyUp(VKey: Byte);
var
ScanCode: Byte;
begin
ScanCode :
=
Lo(MapVirtualKey(VKey,
0
));
keybd_event(VKey, ScanCode, KEYEVENTF_KEYUP,
0
);
end
;
function
BitSet(BitTable, BitMask: Byte): Boolean;
begin
Result :
=
ByteBool(BitTable
and
BitMask);
end
;
var
L: Word;
I: Word;
MKey: Word;
ScanCode: Byte;
const
VKKEYSCANSHIFTON
=
$
01
;
VKKEYSCANCTRLON
=
$
02
;
VKKEYSCANALTON
=
$
04
;
begin
L :
=
StrLen(Keys);
if
L
=
0
then
Exit;
for
I :
=
0
to
L
-
1
do
begin
MKey :
=
vkKeyScan(Keys[I]);
if
MKey
<>
$FFFF
then
begin
ScanCode :
=
Hi(MKey);
if
BitSet(ScanCode, VKKEYSCANSHIFTON)
then
SendKeyDown(VK_SHIFT);
if
BitSet(ScanCode, VKKEYSCANCTRLON)
then
SendKeyDown(VK_CONTROL);
if
BitSet(ScanCode, VKKEYSCANALTON)
then
SendKeyDown(VK_MENU);
SendKeyDown(MKey);
SendKeyUp(MKey);
if
BitSet(ScanCode, VKKEYSCANSHIFTON)
then
SendKeyUp(VK_SHIFT);
if
BitSet(ScanCode, VKKEYSCANCTRLON)
then
SendKeyUp(VK_CONTROL);
if
BitSet(ScanCode, VKKEYSCANALTON)
then
SendKeyUp(VK_MENU);
Sleep(
15
);
//
按键发送间隔,可自行修改
end
;
end
;
end
;
转载于:https://www.cnblogs.com/onroad/archive/2009/08/28/1555854.html