• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • 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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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