• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

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
0
hidrau
Asked:
hidrau
  • 4
  • 3
  • 2
  • +1
1 Solution
 
MerijnBSr. Software EngineerCommented:
try this (assumes the hotkey is a global hotkey!):

procedure TForm11.Button1Click(Sender: TObject);
var Inputs: array of TInput;
begin
 SetLength(Inputs, 4);

 Inputs[0].Itype := INPUT_KEYBOARD;
 Inputs[0].ki.wVk := VK_CONTROL;

 Inputs[1].Itype := INPUT_KEYBOARD;
 Inputs[1].ki.wVk := VK_F12;

 Inputs[2].Itype := INPUT_KEYBOARD;
 Inputs[2].ki.wVk := VK_F12;
 Inputs[2].ki.dwFlags := KEYEVENTF_KEYUP;

 Inputs[3].Itype := INPUT_KEYBOARD;
 Inputs[3].ki.wVk := VK_CONTROL;
 Inputs[3].ki.dwFlags := KEYEVENTF_KEYUP;

 SendInput(4, Inputs[0], SizeOf(TInput));
end;
0
 
diniludCommented:
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;
0
 
diniludCommented:
sorry last one i didn't test. that is not working for me
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
diniludCommented:
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;
0
 
MerijnBSr. Software EngineerCommented:
from the help of keyb_event: Windows NT/2000/XP:This function has been superseded. Use SendInput instead.

0
 
Scay7Commented:
Are you sending this key to your own app or to another application?
0
 
hidrauAuthor Commented:
to my own application and not to another application
0
 
MerijnBSr. Software EngineerCommented:
my solution should work for both local and global hotkeys
0
 
diniludCommented:
If same application then why can't you call the event directly.

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now