Getting keypress when form is inactive (no focus)

  • Thread starter Thread starter kimiraikkonen
  • Start date Start date
K

kimiraikkonen

Hi,
I was working on a screen capturing application which must do its work
when a key (eg: CTRL) is pressed while the application is resides in
tray as a notification icon.

I mean, while my application resides as a notification icon, it must
do the work when a specific key is pressed such as CTRL.

Is it possible to work for an app which hasn't got focus and which is
inactive?

Note: I've done capturing coding part, the thing i want to do is to
implement a kind of keypress listener while user exploring other
windows and my program is inactive as well, but is in the tray bar as
notify icon as minimized.

A good example for my question is that program:
http://www.wisdom-soft.com/downloads/setupscreenhunterfree.zip

Thanks!
 
kimiraikkonen said:
Hi,
I was working on a screen capturing application which must do its
work when a key (eg: CTRL) is pressed while the application is
resides in tray as a notification icon.

I mean, while my application resides as a notification icon, it must
do the work when a specific key is pressed such as CTRL.

Is it possible to work for an app which hasn't got focus and which
is inactive?


http://msdn2.microsoft.com/en-us/library/ms632589(VS.85).aspx

(look for keyboard hooks)


Armin
 
kimiraikkonen said:
So you say i need to call Windows API a kind of p/invoke?

Yes. I think there is no hook support in the Framework.
This link
contains no VB example so i don't know how to declare and which Proc
type i must use.

I don't know it, too. I'd have to read the chapters (see "about
hooks"/"using hooks") in order to learn how to do it. That's how I've always
done it. Probably an option for you, too. Luckily it's all there described
in the MSDN library. If you need a Declare statement, have a look at
www.pinvoke.net


Armin
 
You either need to install a system wide keyboard hook in C++ (not very
smart, and a little tricky) or register a hot key.
Here's how to register a hot key in .NET.http://www.dotnet2themax.com/ShowContent.aspx?ID=103cca7a-0323-47eb-b...
Otherwise do a search for SetWindowsHookEx API and prepare to get your hands
dirty. :-)

Cmoya, that link was "awesome" very thanks, but i need to add
something to facilitate people's work who are searching similiar help.

One thing is missing in article:

If you do not use "Imports System.Runtime.InteropServices" as
declaration, you get "marshal is not declared" error as well. After
this addition, it works.

Thanks.
 
Back
Top