By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,468 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,468 IT Pros & Developers. It's quick & easy.

keyboard hooks in C#

P: n/a
hello all,
I am working on a project related to Internet Explorer. I want my
application to be invoked by a keypress( single key stroke or a
combination). But this must get invoked only when the IE browser is
open. I learnt that SetWindowsHookEx must be used along with few
others. But my doubt is how to call my application? Can i implement the
keyboard hooks related methods in the same project as my application or
should this be else where(i.e as a new project)? wats the difference
between the keyboard hooks and hot keys... i have been serching abt
this for a long time that right now i am confused.
I am new to .NET and all these window hooks. Please help me.
thanks,
hema

Apr 1 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Your app has a dependency upon Internet Explorer. This means that you should
probably build your app so that it launches Internet Explorer when it
starts, rather then depending upon the user to launch Internet Explorer.
Otherwise, this is not something that you can fix by modifying your app, as
your app hasn't started yet before Internet Explorer is required to be
launched.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Hema" <he*********@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
hello all,
I am working on a project related to Internet Explorer. I want my
application to be invoked by a keypress( single key stroke or a
combination). But this must get invoked only when the IE browser is
open. I learnt that SetWindowsHookEx must be used along with few
others. But my doubt is how to call my application? Can i implement the
keyboard hooks related methods in the same project as my application or
should this be else where(i.e as a new project)? wats the difference
between the keyboard hooks and hot keys... i have been serching abt
this for a long time that right now i am confused.
I am new to .NET and all these window hooks. Please help me.
thanks,
hema

Apr 1 '06 #2

P: n/a
Hello, Kevin!

KS> Your app has a dependency upon Internet Explorer. This means that you
KS> should probably build your app so that it launches Internet Explorer
KS> when it starts, rather then depending upon the user to launch Internet
KS> Explorer. Otherwise, this is not something that you can fix by
KS> modifying your app, as your app hasn't started yet before Internet
KS> Explorer is required to be launched.

The solution here can be Browser Helper Object, that will 'live' inside IE and notify main app about different events.


--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Apr 1 '06 #3

P: n/a
hi,
Thanks for the reply! let me explain my project to u first. This is
called Talkative Browser. I have added a button to the IE toolbar. When
the button is pressed,it retrieves the URL of the current web page and
then extracts the HTML source code.From this the Text area is parsed
and sent to MS speech engine to be read out. This is working well with
button click. I want the same functionlity getting invoked when i press
a key. my questions are:
1.is it possible to add a keyboard hook to this project.
2.i cant jus invoke IE , its not my functionality, only after a URL is
launched i can make it speak.so how do i proceed in here.
3.My query earlier was how to add the hook procedure function to the
SetWindowsHookEx in this case. The work starts only after the button is
pressed. i.e Exec of IOleCommandTarget initiates the work after the
button click.

this is my problem.Once again thanks for the reply.
Hema

Apr 1 '06 #4

P: n/a
Yeah, I misunderstood the question. I thought he meant that his app must
start up IE in order to work. It sounds more like he wants to add a keyboard
shortcut to IE to start his app.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hello, Kevin!

KS> Your app has a dependency upon Internet Explorer. This means that you
KS> should probably build your app so that it launches Internet Explorer
KS> when it starts, rather then depending upon the user to launch Internet
KS> Explorer. Otherwise, this is not something that you can fix by
KS> modifying your app, as your app hasn't started yet before Internet
KS> Explorer is required to be launched.

The solution here can be Browser Helper Object, that will 'live' inside IE
and notify main app about different events.
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

Apr 1 '06 #5

P: n/a
Hi Hema,

The following articles may be helpful:

http://www.codeproject.com/system/hooksys.asp
http://www.codeproject.com/csharp/globalsystemhook.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Hema" <he*********@yahoo.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
hi,
Thanks for the reply! let me explain my project to u first. This is
called Talkative Browser. I have added a button to the IE toolbar. When
the button is pressed,it retrieves the URL of the current web page and
then extracts the HTML source code.From this the Text area is parsed
and sent to MS speech engine to be read out. This is working well with
button click. I want the same functionlity getting invoked when i press
a key. my questions are:
1.is it possible to add a keyboard hook to this project.
2.i cant jus invoke IE , its not my functionality, only after a URL is
launched i can make it speak.so how do i proceed in here.
3.My query earlier was how to add the hook procedure function to the
SetWindowsHookEx in this case. The work starts only after the button is
pressed. i.e Exec of IOleCommandTarget initiates the work after the
button click.

this is my problem.Once again thanks for the reply.
Hema

Apr 1 '06 #6

P: n/a
Hello,
Thanks for the links u have provided me.I went thru them.The second article
on Global hooks was very useful.I understood most of the stuff in there.The
first article was highly overwhelming for me. I am new to Window programming
environment and cudn't get wat was there in it. One thing i got was
something related to BHO. I have actully done my Button click invokation and
related works in IObjectWithSite and IOleCommandTarget only. So it was
assuring in some way.

Now as for my doubts after reading the articles are these:
1.As u know, i want my application to detect the keypress after IE is opened.
How to do this? BHO?
2.Is wat i am trying to do some way related to application specific hooks?
(not surely System hooks?)
3.I learnt that SetWindowsHooksEx, InstallHooks,..... are needed for my work.
How will i specify that i want the application i.e. my dll
(TalkativeBrowser.dll- the one i have developed) to get invoked with the
HookProc?
4.Should the hook procedure i will developing be in a separate project?

I might have repeated wat i have been saying in my previous queries. Sorry
abt that. Thats b'coz i am still not able to grasp the idea.

Please help me.
Thanks,
Hema
Apr 3 '06 #7

P: n/a
Hello,
I have used the IObjectWithSite and IOleCommandTarget for my applciation
already.Will this hook that i am adding will come in the IObjectWithSite
again.How different is this going to be?

Thanks,
Hema
Apr 3 '06 #8

P: n/a
I think you are thinking along the right lines with respect to a Browser
Helper Object. There are several different ways to detect a keypress
globally, but that may not be what you really want, and since the dependency
is upon the browser, a BHO would be the most efficient that I can think of.
In addition, you may only want to detect the keypress when the browser has
the focus, which simplifies the process a great deal, since you don't really
need a system hook, but only a hook into the browser's message loop. Is that
the case?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"GEETHA" <LM**@EMAIL.COM> wrote in message
news:00******************************@ureader.com. ..
Hello,
Thanks for the links u have provided me.I went thru them.The second
article
on Global hooks was very useful.I understood most of the stuff in
there.The
first article was highly overwhelming for me. I am new to Window
programming
environment and cudn't get wat was there in it. One thing i got was
something related to BHO. I have actully done my Button click invokation
and
related works in IObjectWithSite and IOleCommandTarget only. So it was
assuring in some way.

Now as for my doubts after reading the articles are these:
1.As u know, i want my application to detect the keypress after IE is
opened.
How to do this? BHO?
2.Is wat i am trying to do some way related to application specific hooks?
(not surely System hooks?)
3.I learnt that SetWindowsHooksEx, InstallHooks,..... are needed for my
work.
How will i specify that i want the application i.e. my dll
(TalkativeBrowser.dll- the one i have developed) to get invoked with the
HookProc?
4.Should the hook procedure i will developing be in a separate project?

I might have repeated wat i have been saying in my previous queries. Sorry
abt that. Thats b'coz i am still not able to grasp the idea.

Please help me.
Thanks,
Hema

Apr 3 '06 #9

P: n/a
hello kevin,
this is Geetha only.I have got some problem with the logging in with my id,..
.. dont know the problem,since i am due to complete my project in few days, i
have created this id.Sorry for the trouble.

Has for the question u have asked.If u mean to say that this message loop
means informing the browser that my application must be invoked when a key
is pressed,then yes thats wat i want.

i have started with the BHO stuff.i think i will call the Hooks related
functionalities i.e. Installhook in IObjectWithSite.SetSite(). then it will
go on as a normal keyboard hook.But how will i call my application's dll
from the HookProc available? mine is not a function right. My application
also uses this same interface to do further processing.i dont know how to do
this and i am struck here.

Hope u get my id and reply back.
Thanks and regards,
geetha
Apr 4 '06 #10

P: n/a
Hi geetha,

Have you seen these articles?

http://www.codeproject.com/csharp/autosig.asp
http://msdn.microsoft.com/library/de...n/html/bho.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"priya" <lm**@email.com> wrote in message
news:f9******************************@ureader.com. ..
hello kevin,
this is Geetha only.I have got some problem with the logging in with my
id,..
. dont know the problem,since i am due to complete my project in few days,
i
have created this id.Sorry for the trouble.

Has for the question u have asked.If u mean to say that this message loop
means informing the browser that my application must be invoked when a key
is pressed,then yes thats wat i want.

i have started with the BHO stuff.i think i will call the Hooks related
functionalities i.e. Installhook in IObjectWithSite.SetSite(). then it
will
go on as a normal keyboard hook.But how will i call my application's dll
from the HookProc available? mine is not a function right. My application
also uses this same interface to do further processing.i dont know how to
do
this and i am struck here.

Hope u get my id and reply back.
Thanks and regards,
geetha

Apr 4 '06 #11

P: n/a
hello Kelvin,
Thanks for identifying me. Yes, i have gone thru these two links already.
There jus talk abt developing a BHO,right? Or am i missing something in
there? I have completed invoking the BHO actually, i have to start with the
Hooking work on.The hook installation must be done in the SetSite method
only right? i.e. after searching whether the BHO is invoked by an IE only.
Am i right? If wrong,plz correct me.
Thanks and regards,
geetha
Apr 5 '06 #12

P: n/a
A Browser Helper Object can handle events spawned by the browser (such as
keyboard input). At least one of those articles tells you how to do this.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"priya" <lm**@email.com> wrote in message
news:f1******************************@ureader.com. ..
hello Kelvin,
Thanks for identifying me. Yes, i have gone thru these two links already.
There jus talk abt developing a BHO,right? Or am i missing something in
there? I have completed invoking the BHO actually, i have to start with
the
Hooking work on.The hook installation must be done in the SetSite method
only right? i.e. after searching whether the BHO is invoked by an IE only.
Am i right? If wrong,plz correct me.
Thanks and regards,
geetha

Apr 5 '06 #13

P: n/a
hello,
i have implemented the BHO and keyboard hooks successfully, the hook is
getting inserting but after the IE opens, there is no response when i press
my keys. The combinations for the keys are these.

wat could be wrong?
i can show u my code also, please tell me.
thanks and regards,
geetha
Apr 6 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.