how to set application-wide keyboard handling?

  • Thread starter Thread starter assaf
  • Start date Start date
A

assaf

hi all

i have a 2 winforms in my app.
one is the owner of the other.

i capture keyboard events for
each form.

can i instead tell the entire 'app'
to respond to certain keys.
and not have to tell each form to handle the keys.

i actually have over 20 forms,
so handling keys for each form
would be a lot of dirty work.


assaf
 
Not sure whether I have understood correctly. But can't you write a base
form in which you capture the KeyPress event and derive all the other forms
from the base form?

+Rajesh R
 
Other possibility would be install a message filter. Take a look on
IMessageFilter and Application.AddMessageFilter. In this case, however, you
deal with windows messages rather than events. Pay attention on the CAUTION
section in the docs. It says that isntalling message filter can hurt the
performance.

This is the only place where you can intercept windows notifications
globally for the UI thread. But be adviced that you can catch only events
that comes thru the message pump (those are more or less messages form the
keyboard and the mouse). Most of the messages are sent and they don't go
thru the message queue
 
bingo


Stoitcho Goutsev (100) said:
Other possibility would be install a message filter. Take a look on
IMessageFilter and Application.AddMessageFilter. In this case, however, you
deal with windows messages rather than events. Pay attention on the CAUTION
section in the docs. It says that isntalling message filter can hurt the
performance.

This is the only place where you can intercept windows notifications
globally for the UI thread. But be adviced that you can catch only events
that comes thru the message pump (those are more or less messages form the
keyboard and the mouse). Most of the messages are sent and they don't go
thru the message queue

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Rajesh R said:
Not sure whether I have understood correctly. But can't you write a base
form in which you capture the KeyPress event and derive all the other
forms
from the base form?

+Rajesh R
 
Back
Top