Discussion:
Capturing keyboard shortcuts on my appplication
(too old to reply)
Darío Alejandro Guzik
2008-06-26 18:32:01 UTC
Permalink
Hi!

I like to define keyboard shortcuts to do some actions in my application
and I like o know how to do this. The application is an MDI forms
application and the shortcuts should wotk with any form in focus.
Is there a way to do this without adding a KeyDown event on every form?

Thanks
Remy Lebeau (TeamB)
2008-06-26 19:08:04 UTC
Permalink
Post by Darío Alejandro Guzik
I like to define keyboard shortcuts to do some actions in
my application and I like o know how to do this.
Look at the Win32 API RegisterHotKey() function.


Gambit
Darío Alejandro Guzik
2008-06-26 20:32:04 UTC
Permalink
Post by Remy Lebeau (TeamB)
Post by Darío Alejandro Guzik
I like to define keyboard shortcuts to do some actions in
my application and I like o know how to do this.
Look at the Win32 API RegisterHotKey() function.
Thanks. Sorry to bother you again but I cannot find the documentation.
Correct me if I wrong:
Ex: I want to capture CTRL-P as a hot key, so in my form, when I create
it I add:

RegisterHotKey(this->Handle, 101, MOD_CONTROL, VK_P);

and I have to add a listener to that message in this form

protected:
void __fastcall FormHotKey(TMessage &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_HOTKEY, TMessage, FormHotKey)
END_MESSAGE_MAP(TForm);

and that should be enough?

When I press CTRL-P on any window this method should be triggered?
Post by Remy Lebeau (TeamB)
Gambit
Darío Alejandro Guzik
2008-06-26 21:11:00 UTC
Permalink
Never mind... I was usign the wrong virtual code. It works!

Thanks for the advice on the API function
Post by Darío Alejandro Guzik
Post by Remy Lebeau (TeamB)
Post by Darío Alejandro Guzik
I like to define keyboard shortcuts to do some actions in
my application and I like o know how to do this.
Look at the Win32 API RegisterHotKey() function.
Thanks. Sorry to bother you again but I cannot find the documentation.
Ex: I want to capture CTRL-P as a hot key, so in my form, when I create
RegisterHotKey(this->Handle, 101, MOD_CONTROL, VK_P);
and I have to add a listener to that message in this form
void __fastcall FormHotKey(TMessage &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_HOTKEY, TMessage, FormHotKey)
END_MESSAGE_MAP(TForm);
and that should be enough?
When I press CTRL-P on any window this method should be triggered?
Post by Remy Lebeau (TeamB)
Gambit
DreamChaser
2008-06-27 06:23:45 UTC
Permalink
Post by Darío Alejandro Guzik
Never mind... I was usign the wrong virtual code. It works!
And the answer is? :) Thanks :)
Sabetay Toros
2008-06-27 12:32:59 UTC
Permalink
Post by Darío Alejandro Guzik
Post by Remy Lebeau (TeamB)
Post by Darío Alejandro Guzik
I like to define keyboard shortcuts to do some actions in
my application and I like o know how to do this.
Look at the Win32 API RegisterHotKey() function.
Thanks. Sorry to bother you again but I cannot find the documentation.
Ex: I want to capture CTRL-P as a hot key, so in my form, when I create
RegisterHotKey(this->Handle, 101, MOD_CONTROL, VK_P);
and I have to add a listener to that message in this form
void __fastcall FormHotKey(TMessage &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_HOTKEY, TMessage, FormHotKey)
END_MESSAGE_MAP(TForm);
and that should be enough?
When I press CTRL-P on any window this method should be triggered?
Post by Remy Lebeau (TeamB)
Gambit
There is an event OnKeyDown in the TForm component.

It's enough to write a function like that.

void __fastcall TForm::FormKeyDown(TObject *Sender, Word &Key,
TShiftState Shift)
{
if (Key == VK_P) ...

}
And dont forget to include

KeyPreview = true;

in the forms constructer

Sabetay



Sabetay

Loading...