I need to do the right key combination SHIFT + CTR, then enter any symbol, let's it be 'a'
I used this code:
keybd_event (VK_RCONTROL, 0, WM_KEYDOWN, 0);
keybd_event (VK_RSHIFT, 0, WM_KEYDOWN, 0);
keybd_event (VK_RCONTROL, 0, WM_KEYUP, 0);
keybd_event (VK_RSHIFT, 0, WM_KEYUP, 0);
keybd_event (32,0, WM_KEYDOWN, 0);
keybd_event (32,0, WM_KEYUP, 0);
by pressing the keyboard shortcut does not work, but into the foreign window only putted two 'a' symbols,
What I doing wrong?
Delphi 7!? how to emulate pressing the right key combination CTRL + SHIFT
Started by Stasonix, Jan 01 2012 01:13 PM
1 reply to this topic
#1
Posted 01 January 2012 - 01:13 PM
|
|
|
#2
Posted 10 April 2012 - 07:40 AM
"Real" keyboard simulation is real tricky. You are not suppose to treat special keys (e.g. ctrl and shift) like ordinary char key. They must be used as flags. Let me dig my sample codes.
Okay, you can use this code to simulate key pressing. The last time I check it handles special keys properly.
Okay, you can use this code to simulate key pressing. The last time I check it handles special keys properly.
{*******************************************************************************
* Procedure PostKeyEx32
*
* Parameters:
* AKey : virtual keycode of the key to send. For printable
* keys this is simply the ANSI code (Ord(character)).
* AShift : state of the modifier keys. This is a set, so you
* can set several of these keys (shift, control, alt,
* mouse buttons) in tandem. The TShiftState type is
* declared in the Classes Unit.
* AIsSpecialkey:
* normally this should be False. Set it to True to
* specify a key on the numeric keypad, for example.
* Description:
* Uses keybd_event to manufacture a series of key events matching
* the passed parameters. The events go to the control with focus.
* Note that for characters key is always the upper-case version of
* the character. Sending without any modifier keys will result in
* a lower-case character, sending it with [ssShift] will result
* in an upper-case character!
*
* Created: 17.7.98 by P. Below
******************************************************************************}
procedure PostKeyEx32(AKey: Word; const AShift: TShiftState;
const AIsSpecialKey: Boolean);
type
TShiftKeyInfo = record
Shift: Byte;
VKey : Byte;
end;
ByteSet = set of 0..7;
const
ShiftKeys: array [1..3] of TShiftKeyInfo =
((Shift: Ord(ssCtrl) ; VKey: VK_CONTROL ),
(Shift: Ord(ssShift); VKey: VK_SHIFT ),
(Shift: Ord(ssAlt) ; VKey: VK_MENU ));
var
i: Integer;
vFlag : DWORD;
vShift: ByteSet absolute AShift;
begin
for i := 1 to 3 do
begin
if ShiftKeys[i].Shift in vShift then
keybd_event(ShiftKeys[i].VKey
, MapVirtualKey(ShiftKeys[i].VKey, 0)
, 0
, 0);
end;
if AIsSpecialkey Then
vFlag := KEYEVENTF_EXTENDEDKEY
else
vFlag := 0;
keybd_event(AKey, MapvirtualKey(AKey, 0), vFlag, 0);
vFlag := vFlag or KEYEVENTF_KEYUP;
keybd_event(AKey, MapvirtualKey(AKey, 0), vFlag, 0);
for i := 3 downto 1 do
begin
if ShiftKeys[i].Shift in vShift then
keybd_event(ShiftKeys[i].VKey
, MapVirtualKey(ShiftKeys[i].VKey, 0)
, KEYEVENTF_KEYUP
, 0);
end;
end;
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









