Keyboard hook and global variables 
Author Message
 Keyboard hook and global variables

I need to detect a period of inactivity of mouse and keyboard.

I've got a keyboard hook running in CW(thanks, Paul Attryde) which
detects mouse and keyboard activity. But attempts to store the time of
last activity in a module or global CW variable (in the dll with the
hook procedure) fail, this variable's being constantly reinitialised.

Seems I need to use the system memory area to pass values between the
hook and the rest of the dll. According to posts here I can use

- PEEK() and POKE() - ok, but what memory address is it safe to use,
or

- GlobalAlloc, GlobalLock etc.

Can anybody help with a first-grade guide to these functions?

TIA
Rhys



Tue, 28 Sep 2004 19:27:24 GMT  
 Keyboard hook and global variables
Rhys,

Have you tried using globals marked as STATIC?
That's about the only thing that works for me.

--
Paul Attryde
www.attryde.com
www.attryde.com/clarion


Quote:
> I need to detect a period of inactivity of mouse and keyboard.

> I've got a keyboard hook running in CW(thanks, Paul Attryde) which
> detects mouse and keyboard activity. But attempts to store the time of
> last activity in a module or global CW variable (in the dll with the
> hook procedure) fail, this variable's being constantly reinitialised.

> Seems I need to use the system memory area to pass values between the
> hook and the rest of the dll. According to posts here I can use

> - PEEK() and POKE() - ok, but what memory address is it safe to use,
> or

> - GlobalAlloc, GlobalLock etc.

> Can anybody help with a first-grade guide to these functions?

> TIA
> Rhys



Thu, 30 Sep 2004 01:58:16 GMT  
 Keyboard hook and global variables
Thanks again, Paul.

That's a step forward, but the hook's only detecting keyboard and
mouse activity in the app that establishes the hook.

My hook procedure's in a dll and the proc is called from a cw .exe.

How do I get it to monitor system-wide activity?

TIA
Rhys


Quote:
> Rhys,

> Have you tried using globals marked as STATIC?
> That's about the only thing that works for me.



Fri, 01 Oct 2004 05:20:17 GMT  
 Keyboard hook and global variables
Rhys,

Look at the last param of SetWindowsHookEx() - it's the thread number of the
thread to install the hook on.
I assume right now you're probably setting it to the thread ID of your app,
either using Prop:Instance or GetThreadID() APi call?

You should be able to get all active processes in the current desktop by
setting it to 0, but be warned that CW also installs/removes hooks during
the life of your app.

If you get an API monitor ( like http://www.rohitab.com/apimonitor ) you
should be able to see what type of hook the RTL installs

I'll be honest and say I've had limited success with it, which is why I only
install thread-specific hooks.
Depending on what you're doing it might be easier to use VC++
--
Paul


Quote:
> Thanks again, Paul.

> That's a step forward, but the hook's only detecting keyboard and
> mouse activity in the app that establishes the hook.

> My hook procedure's in a dll and the proc is called from a cw .exe.

> How do I get it to monitor system-wide activity?

> TIA
> Rhys




Quote:
> > Rhys,

> > Have you tried using globals marked as STATIC?
> > That's about the only thing that works for me.



Sat, 02 Oct 2004 08:15:54 GMT  
 Keyboard hook and global variables
Paul,

I have the last parameter set to zero. I can prove that the hook is
actually working across all apps by writing to a file when it fires.
But that gets ugly pretty fast - just moving the mouse across the
screen gives the file a serious workout.

So it looks like I need to exchange data between apps via system
memory. Whaddya know, ClarionMag has an article on doing exactly that
with file mappings, next week! (Nice timing, John Gorter.)

Quote:
> VC++

hey, I have enough trouble with English!

Cheers
Rhys


Quote:
> Rhys,

> Look at the last param of SetWindowsHookEx() - it's the thread number of the
> thread to install the hook on.
> I assume right now you're probably setting it to the thread ID of your app,
> either using Prop:Instance or GetThreadID() APi call?



Sun, 03 Oct 2004 19:43:01 GMT  
 Keyboard hook and global variables
Rhys,

See if this helps
www.mooremvp.freeserve.co.uk/Win32/framed_tip004.htm

I don't think CW can do shared segments (IIRC it was a design decision a
long time ago) so maybe this is why it isn't working?

--
Paul


Quote:
> Paul,

> I have the last parameter set to zero. I can prove that the hook is
> actually working across all apps by writing to a file when it fires.
> But that gets ugly pretty fast - just moving the mouse across the
> screen gives the file a serious workout.

> So it looks like I need to exchange data between apps via system
> memory. Whaddya know, ClarionMag has an article on doing exactly that
> with file mappings, next week! (Nice timing, John Gorter.)

> > VC++
> hey, I have enough trouble with English!

> Cheers
> Rhys




- Show quoted text -

Quote:
> > Rhys,

> > Look at the last param of SetWindowsHookEx() - it's the thread number of
the
> > thread to install the hook on.
> > I assume right now you're probably setting it to the thread ID of your
app,
> > either using Prop:Instance or GetThreadID() APi call?



Mon, 11 Oct 2004 07:39:42 GMT  
 Keyboard hook and global variables
I wimped out - using the WH_Mouse_LL and WH_Keyboard_LL parameters for
SetWindowsHookEx gives access to system-wide threads, but only on
Windoze other than 95/98/ME.

thanks again
Rhys


Quote:
> Rhys,

> See if this helps
> www.mooremvp.freeserve.co.uk/Win32/framed_tip004.htm

> I don't think CW can do shared segments (IIRC it was a design decision a
> long time ago) so maybe this is why it isn't working?

<snip>
 Paul


Mon, 11 Oct 2004 21:53:32 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. global keyboard hook

2. Class variables / global variables / Init variables

3. Keyboard hooks in VisualAge

4. need help with keyboard hook

5. Keyboard Hook instead of Alert?

6. KEYBOARD INT HOOK

7. KEYBOARD INT HOOK

8. global hook function not working

9. Global Variable / Sessions / ASP Application type Variable

10. TK keyboard input bug w/ MS Global IME

11. Global variables at the Address Space level

12. Global variables

 

 
Powered by phpBB® Forum Software