Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

trigger a hotkey through button

Hello guys,

I need a way to trigger a hotkey = Ctrl + F12

when I click on a button it must trigger this hotkey, how can I do this?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of MerijnB
MerijnB
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
procedure TForm11.Button1Click(Sender: TObject);
begin
  SendMessageA(Form1.Handle, WM_KEYDOWN, VK_CONTROL, 0);
  SendMessageA(Form1.Handle, WM_KEYDOWN, VK_F12, 0);
  SendMessageA(Form1.Handle, WM_KEYUP, VK_F12, 0);
  SendMessageA(Form1.Handle, WM_KEYUP, VK_CONTROL, 0);
end;
sorry last one i didn't test. that is not working for me
procedure TForm2.Button1Click(Sender: TObject);
begin
  keybd_event(VK_CONTROL,0 ,0, 0) ;
  keybd_event(VK_F5,0 ,0, 0) ;
  keybd_event(VK_F5,0 ,KEYEVENTF_KEYUP, 0) ;
  keybd_event(VK_CONTROL,0 ,KEYEVENTF_KEYUP, 0) ;
end;
from the help of keyb_event: Windows NT/2000/XP:This function has been superseded. Use SendInput instead.

Are you sending this key to your own app or to another application?
Avatar of hidrau

ASKER

to my own application and not to another application
my solution should work for both local and global hotkeys
If same application then why can't you call the event directly.

eg: Form1.Menu1.click;
Ye was gona say rather just call that button that was assigned to the alt-f12