Teclado - enviando teclas para o buffer |
Top Previous Next |
// Enviando combinação de teclas para o buffer do teclado // Exemplo : PostKeyEx32(Ord('A'), [ssCtrl], false); // Envia Ctrl+A para o controle que tiver o foco. // Key : virtual keycode da tecla a enviar. Para caracteres // imprimíveis informe o código ANSI (Ord(CHARACTER)). // Shift : estado das teclas modificadoras. // Shift, Control, Alt, Mouse Buttons. // SpecialKey: normalmente deve ser False. Informe True se // a tecla desejada for, por exemplo, do teclado numérico. procedure PostKeyEx32(Key: Word; const Shift: TShiftState; SpecialKey: 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 Flag: DWORD; bShift: ByteSet absolute shift; i: Integer; begin for i := 1 to 3 do if shiftkeys[i].shift in bShift then Keybd_Event(ShiftKeys[i].vkey, MapVirtualKey(ShiftKeys[i].vkey, 0), 0, 0);
if SpecialKey Then Flag := KEYEVENTF_EXTENDEDKEY else Flag := 0;
Keybd_Event(Key, MapvirtualKey(Key, 0), Flag, 0); Flag := Flag or KEYEVENTF_KEYUP; Keybd_Event(Key, MapvirtualKey(Key, 0), Flag, 0); for i := 3 downto 1 do if ShiftKeys[i].shift in bShift then Keybd_Event(shiftkeys[i].vkey, MapVirtualKey(ShiftKeys[i].vkey, 0), KEYEVENTF_KEYUP, 0); end;
procedure Click; begin PostKeyEx32(Vk_Tab, [ssAlt], False); end; |