Keyboard events in none forms applications...

  • Thread starter Thomas Johansen
  • Start date
T

Thomas Johansen

Hi

I have tried finding the answer on the above. The only way of receiving
keyboard event in C# is to be a form and have focus. But isnt there any
other way of get keyboard events in non forms C# application ?
I guess i can use win32 hooks, but to my knowledge, its not global, so
application still need to have focus ??
Its ok for me, if I have to use win32 API's in my C# application or add some
managed C++ part, for gettings those events.!!

Any suggestions ?

/Thomas
 
P

Paul G. Tobey [eMVP]

There has to be a focused window or the key events would never be sent to
you (you've specifically said that you don't want them, if you don't own the
focused window).

Tell us *what* you want to do, rather than how you want to do it. We'll be
better at helping you.

Paul T.
 
T

Thomas Johansen

I would like to make it possible for some code in a Dll, to receive some
keyevents, so it can react upon them, and not just the dialog in focus.
Is that possible ?


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
 
P

Paul G. Tobey [eMVP]

Maybe, but why? Again, you're telling us *how* you want to do something
without telling us what it is that you want to do. You have an existing
application that you lost the source code for and you need to change how it
sets up the default values in a dialog? You're building a test utility to
automatically perform operations on a dialog in an application-under-test?
You're just curious? What?

Paul T.

Thomas Johansen said:
I would like to make it possible for some code in a Dll, to receive some
keyevents, so it can react upon them, and not just the dialog in focus.
Is that possible ?


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
There has to be a focused window or the key events would never be sent to
you (you've specifically said that you don't want them, if you don't own
the focused window).

Tell us *what* you want to do, rather than how you want to do it. We'll
be better at helping you.

Paul T.
 
T

Thomas Johansen

If a user presses a certain key, I not just whant the GUI to react, but
allso some underlying code.
Yes, the GUi could send down the key when it was pressed, but its not
allways that program that has focus (Or is shown for that matter). The code
must react no matter what has focus....!!!

/Thomas


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
Maybe, but why? Again, you're telling us *how* you want to do something
without telling us what it is that you want to do. You have an existing
application that you lost the source code for and you need to change how
it sets up the default values in a dialog? You're building a test utility
to automatically perform operations on a dialog in an
application-under-test? You're just curious? What?

Paul T.

Thomas Johansen said:
I would like to make it possible for some code in a Dll, to receive some
keyevents, so it can react upon them, and not just the dialog in focus.
Is that possible ?


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message news:[email protected]...
There has to be a focused window or the key events would never be sent
to you (you've specifically said that you don't want them, if you don't
own the focused window).

Tell us *what* you want to do, rather than how you want to do it. We'll
be better at helping you.

Paul T.


Hi

I have tried finding the answer on the above. The only way of receiving
keyboard event in C# is to be a form and have focus. But isnt there any
other way of get keyboard events in non forms C# application ?
I guess i can use win32 hooks, but to my knowledge, its not global, so
application still need to have focus ??
Its ok for me, if I have to use win32 API's in my C# application or add
some managed C++ part, for gettings those events.!!

Any suggestions ?

/Thomas
 
P

Paul G. Tobey [eMVP]

RegisterHotKey() is the only reasonable way to make this work, but it's not
reasonable to catch all keys that way. I suppose that you might try using a
native library and SetWindowsHookEx() to catch the low-level keyboard event
and then send a message to your managed code. I'm inclined to think that
your scheme is not going to make much sense to an average user (I'm typing a
contact name into the address book and all of a sudden, some random process
is jumping in and doing something).

Paul T.

Thomas Johansen said:
If a user presses a certain key, I not just whant the GUI to react, but
allso some underlying code.
Yes, the GUi could send down the key when it was pressed, but its not
allways that program that has focus (Or is shown for that matter). The
code must react no matter what has focus....!!!

/Thomas


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
Maybe, but why? Again, you're telling us *how* you want to do something
without telling us what it is that you want to do. You have an existing
application that you lost the source code for and you need to change how
it sets up the default values in a dialog? You're building a test
utility to automatically perform operations on a dialog in an
application-under-test? You're just curious? What?

Paul T.

Thomas Johansen said:
I would like to make it possible for some code in a Dll, to receive some
keyevents, so it can react upon them, and not just the dialog in focus.
Is that possible ?


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message There has to be a focused window or the key events would never be sent
to you (you've specifically said that you don't want them, if you don't
own the focused window).

Tell us *what* you want to do, rather than how you want to do it.
We'll be better at helping you.

Paul T.


Hi

I have tried finding the answer on the above. The only way of
receiving keyboard event in C# is to be a form and have focus. But
isnt there any other way of get keyboard events in non forms C#
application ?
I guess i can use win32 hooks, but to my knowledge, its not global, so
application still need to have focus ??
Its ok for me, if I have to use win32 API's in my C# application or
add some managed C++ part, for gettings those events.!!

Any suggestions ?

/Thomas
 
T

Thomas Johansen

Hi again...

I dont need to catch all keys. Just a few.
Its a industrial embedded target with few keys. Actually its not a real
keyboard, but a thin keypad with 10 buttons, but its mapped as a keyboard.
So if specific keys are pressed (e.g. ESC), then the underlying process must
know to terminate what it is doing...


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
RegisterHotKey() is the only reasonable way to make this work, but it's
not reasonable to catch all keys that way. I suppose that you might try
using a native library and SetWindowsHookEx() to catch the low-level
keyboard event and then send a message to your managed code. I'm inclined
to think that your scheme is not going to make much sense to an average
user (I'm typing a contact name into the address book and all of a sudden,
some random process is jumping in and doing something).

Paul T.

Thomas Johansen said:
If a user presses a certain key, I not just whant the GUI to react, but
allso some underlying code.
Yes, the GUi could send down the key when it was pressed, but its not
allways that program that has focus (Or is shown for that matter). The
code must react no matter what has focus....!!!

/Thomas


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message news:[email protected]...
Maybe, but why? Again, you're telling us *how* you want to do something
without telling us what it is that you want to do. You have an existing
application that you lost the source code for and you need to change how
it sets up the default values in a dialog? You're building a test
utility to automatically perform operations on a dialog in an
application-under-test? You're just curious? What?

Paul T.

I would like to make it possible for some code in a Dll, to receive some
keyevents, so it can react upon them, and not just the dialog in focus.
Is that possible ?


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message There has to be a focused window or the key events would never be sent
to you (you've specifically said that you don't want them, if you
don't own the focused window).

Tell us *what* you want to do, rather than how you want to do it.
We'll be better at helping you.

Paul T.


Hi

I have tried finding the answer on the above. The only way of
receiving keyboard event in C# is to be a form and have focus. But
isnt there any other way of get keyboard events in non forms C#
application ?
I guess i can use win32 hooks, but to my knowledge, its not global,
so application still need to have focus ??
Its ok for me, if I have to use win32 API's in my C# application or
add some managed C++ part, for gettings those events.!!

Any suggestions ?

/Thomas
 
P

Paul G. Tobey [eMVP]

Then it may be OK for you do it with hot keys. You should probably
prototype it before deciding that it's the way to go. You could do the same
with SetWindowsHookEx() for comparison and then integrate whichever seems
better into the final design.

Paul T.

Thomas Johansen said:
Hi again...

I dont need to catch all keys. Just a few.
Its a industrial embedded target with few keys. Actually its not a real
keyboard, but a thin keypad with 10 buttons, but its mapped as a keyboard.
So if specific keys are pressed (e.g. ESC), then the underlying process
must know to terminate what it is doing...


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
RegisterHotKey() is the only reasonable way to make this work, but it's
not reasonable to catch all keys that way. I suppose that you might try
using a native library and SetWindowsHookEx() to catch the low-level
keyboard event and then send a message to your managed code. I'm
inclined to think that your scheme is not going to make much sense to an
average user (I'm typing a contact name into the address book and all of
a sudden, some random process is jumping in and doing something).

Paul T.

Thomas Johansen said:
If a user presses a certain key, I not just whant the GUI to react, but
allso some underlying code.
Yes, the GUi could send down the key when it was pressed, but its not
allways that program that has focus (Or is shown for that matter). The
code must react no matter what has focus....!!!

/Thomas


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message Maybe, but why? Again, you're telling us *how* you want to do
something without telling us what it is that you want to do. You have
an existing application that you lost the source code for and you need
to change how it sets up the default values in a dialog? You're
building a test utility to automatically perform operations on a dialog
in an application-under-test? You're just curious? What?

Paul T.

I would like to make it possible for some code in a Dll, to receive
some keyevents, so it can react upon them, and not just the dialog in
focus.
Is that possible ?


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message
There has to be a focused window or the key events would never be
sent to you (you've specifically said that you don't want them, if
you don't own the focused window).

Tell us *what* you want to do, rather than how you want to do it.
We'll be better at helping you.

Paul T.


Hi

I have tried finding the answer on the above. The only way of
receiving keyboard event in C# is to be a form and have focus. But
isnt there any other way of get keyboard events in non forms C#
application ?
I guess i can use win32 hooks, but to my knowledge, its not global,
so application still need to have focus ??
Its ok for me, if I have to use win32 API's in my C# application or
add some managed C++ part, for gettings those events.!!

Any suggestions ?

/Thomas
 
T

Thomas Johansen

Hey Paul

Ok.. It will try that. You mention hot keys. Are they different than
"normal" keys ?

How are they handled ? allso by SetWindowsHookEx() ??

/Thomas

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
Then it may be OK for you do it with hot keys. You should probably
prototype it before deciding that it's the way to go. You could do the
same with SetWindowsHookEx() for comparison and then integrate whichever
seems better into the final design.

Paul T.

Thomas Johansen said:
Hi again...

I dont need to catch all keys. Just a few.
Its a industrial embedded target with few keys. Actually its not a real
keyboard, but a thin keypad with 10 buttons, but its mapped as a
keyboard. So if specific keys are pressed (e.g. ESC), then the underlying
process must know to terminate what it is doing...


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message news:[email protected]...
RegisterHotKey() is the only reasonable way to make this work, but it's
not reasonable to catch all keys that way. I suppose that you might try
using a native library and SetWindowsHookEx() to catch the low-level
keyboard event and then send a message to your managed code. I'm
inclined to think that your scheme is not going to make much sense to an
average user (I'm typing a contact name into the address book and all of
a sudden, some random process is jumping in and doing something).

Paul T.

If a user presses a certain key, I not just whant the GUI to react, but
allso some underlying code.
Yes, the GUi could send down the key when it was pressed, but its not
allways that program that has focus (Or is shown for that matter). The
code must react no matter what has focus....!!!

/Thomas


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message Maybe, but why? Again, you're telling us *how* you want to do
something without telling us what it is that you want to do. You have
an existing application that you lost the source code for and you need
to change how it sets up the default values in a dialog? You're
building a test utility to automatically perform operations on a
dialog in an application-under-test? You're just curious? What?

Paul T.

I would like to make it possible for some code in a Dll, to receive
some keyevents, so it can react upon them, and not just the dialog in
focus.
Is that possible ?


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no
spam DOT com> wrote in message
There has to be a focused window or the key events would never be
sent to you (you've specifically said that you don't want them, if
you don't own the focused window).

Tell us *what* you want to do, rather than how you want to do it.
We'll be better at helping you.

Paul T.


Hi

I have tried finding the answer on the above. The only way of
receiving keyboard event in C# is to be a form and have focus. But
isnt there any other way of get keyboard events in non forms C#
application ?
I guess i can use win32 hooks, but to my knowledge, its not global,
so application still need to have focus ??
Its ok for me, if I have to use win32 API's in my C# application or
add some managed C++ part, for gettings those events.!!

Any suggestions ?

/Thomas
 
G

Guest

They are "handled" by registering a key as a hot key:

http://msdn.microsoft.com/library/en-us/wceui40/html/cerefRegisterHotKey.asp?frame=true


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Thomas Johansen said:
Hey Paul

Ok.. It will try that. You mention hot keys. Are they different than
"normal" keys ?

How are they handled ? allso by SetWindowsHookEx() ??

/Thomas

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
Then it may be OK for you do it with hot keys. You should probably
prototype it before deciding that it's the way to go. You could do the
same with SetWindowsHookEx() for comparison and then integrate whichever
seems better into the final design.

Paul T.

Thomas Johansen said:
Hi again...

I dont need to catch all keys. Just a few.
Its a industrial embedded target with few keys. Actually its not a real
keyboard, but a thin keypad with 10 buttons, but its mapped as a
keyboard. So if specific keys are pressed (e.g. ESC), then the
underlying process must know to terminate what it is doing...


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message RegisterHotKey() is the only reasonable way to make this work, but it's
not reasonable to catch all keys that way. I suppose that you might
try using a native library and SetWindowsHookEx() to catch the
low-level keyboard event and then send a message to your managed code.
I'm inclined to think that your scheme is not going to make much sense
to an average user (I'm typing a contact name into the address book and
all of a sudden, some random process is jumping in and doing
something).

Paul T.

If a user presses a certain key, I not just whant the GUI to react,
but allso some underlying code.
Yes, the GUi could send down the key when it was pressed, but its not
allways that program that has focus (Or is shown for that matter). The
code must react no matter what has focus....!!!

/Thomas


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message
Maybe, but why? Again, you're telling us *how* you want to do
something without telling us what it is that you want to do. You
have an existing application that you lost the source code for and
you need to change how it sets up the default values in a dialog?
You're building a test utility to automatically perform operations on
a dialog in an application-under-test? You're just curious? What?

Paul T.

I would like to make it possible for some code in a Dll, to receive
some keyevents, so it can react upon them, and not just the dialog in
focus.
Is that possible ?


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no
spam DOT com> wrote in message
There has to be a focused window or the key events would never be
sent to you (you've specifically said that you don't want them, if
you don't own the focused window).

Tell us *what* you want to do, rather than how you want to do it.
We'll be better at helping you.

Paul T.


Hi

I have tried finding the answer on the above. The only way of
receiving keyboard event in C# is to be a form and have focus. But
isnt there any other way of get keyboard events in non forms C#
application ?
I guess i can use win32 hooks, but to my knowledge, its not
global, so application still need to have focus ??
Its ok for me, if I have to use win32 API's in my C# application
or add some managed C++ part, for gettings those events.!!

Any suggestions ?

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top