jpierson,
Sorry, but I don't know if I can help you with that. Frankly I don't
understand your problem. If you could post some simple compilable code that
somehow demostrates your problem that would probably be the best. As far as
I can see I'm the only one that keep posting in your thread probably the
rest in the ng don't understand the problem as well.
There are two types of keyboard hooks: WH_KEYBOARD and WH_KEYBOARD_LL.
WH_KEYBOARD_LL is possible to implement in .NET. This is a golbal hook and
it intercepts all key events before they to be dispatched to any
application. I don't think you are interested in that.
WH_KEYBOARD intercepts WM_KEYDOWN and WM_KEYUP messages as they are
retreived form the message queue of a UI thread.
This keyboard hook can be implemented in .NET only to hook on threads
created by the same process as the hook procedure code. In .NET you cannot
set this hook gloabally, neither you can hook on to a thread created in
different process. I'm not sure though bout the latter, never tried it;
maybe you hook on to a thread in a process that runs the CLR; it might be
possible I don't know, but frankly I doubt it.
It looks more that you are after WM_KEYBOARD hook. As I said you can use it
to hook only threads in your process, so I was thinking isn't it possible to
do it differently then (for example with message loop filters or overriding
WndProc method.
Anyways, if you havent read this MSDN doc about hooks yet, take a look at
it
http://msdn.microsoft.com/library/de...usinghooks.asp
You can find there the skeleton of a WH_KEYBOARD procedure. It is native
code, but translation to C# must be really straightforward.
When you implement the skeleton then upon HC_ACTION you can check the wParam
for the virtual codes of the Break and Ctrl keys. The codes are the same as
Keys.Pause and Keys.ControlKey.
In the hook you are going to receive info from the raw WM_KEYDOWN and
WM_KEYUP that means you need to listen for pressing first the Ctrl key, set
a flag internally and then wait for the Break key. You won't receive one
combined code for Ctrl+Break. Whether the key is pressed or released you can
find your form the 31th bit in the lParam: 1. the key is released and 0 the
key is pressed.
Keep in mind thought that you need to check the *code* for PM_NOREMOVE also.
If the code is PM_NOREMOVE that means the WM_KEY* message stays in the
message queue and you will probably receive one more notification for the
same key. This happens when the message luup only peeks for a message.
I hope you'll find this information helpful, but again my advice is to keep
hooks only as a last option. Settings hooks requires P/Invoke which has to
be avoided in managed applications.
--
HTH
Stoitcho Goutsev (100)
<jp******@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi Stoitcho ,
I have something similar already the reason I am using a keyboard hook
is that ctrl + pause/break is a special key sequence and it won't work
just using the send keys class.
I have to hook it to the application in order for it to be recognised i
just don't know how to implement it properly in order for it to work
with my application.
Thanks
James