Click recorder in cf

T

techiechic

Hi to all! I am creating an application for testing the UI that can
record and simulate all the clicks done on any application. I have
successfully done it in desktop using hooks, can I do the same in
compact framework? I want to record all clicks and its coordinates in
order to playback or simulate all the recorded clicks.

Any help will be very much appreciated..
 
T

techiechic

I already figured out how to send mouse clicks.. My problem now is how
to capture mouse messages globally? Thanks..
 
P

Paul G. Tobey [eMVP]

That's the problem; you can't, without some low-level code. You could try
to make a journaling hook in .NET CF and use SetWindowsHookEx() to install
it. Windows CE really wasn't designed to give you all that flexibility that
you have on the desktop, though; it's too costly in terms of execution speed
on the small processors that are often used with CE.

Paul T.
 
T

techiechic

I already tried that using the mouse hook and it always fails to set
the hook. Is there any other way?
 
P

Paul G. Tobey [eMVP]

You could P/Invoke to your own native DLL where you would also get called
back. The DLL could then use any one of a number of methods to get the data
back to the managed code...

Paul T.
 
P

Paul G. Tobey [eMVP]

We don't know how it works in C#, at least to the point of creating an
example. That's the part of this project that belongs to you. As Chris
previously said, you can't do it in 1.0 at all. You are using a later
version of .NET CF than that?

Paul T.
 
T

techiechic

Its ok for me to do it net cf 2.0. I just don't know how to implement
it in c#. I am not familiar with c++ programming. Can you translate
this to c# for me.

EVENTMSG evtMsg;
ZeroMemory(&evtMsg, sizeof(EVENTMSG));
HHOOK hh = pfSetWindowsHook(WH_JOURNALRECORD, JournalRecordProc,
&evtMsg);


typedef struct tagEVENTMSG {
UINT message;
UINT paramL;
UINT paramH;
DWORD time;
HWND hwnd;

} EVENTMSG;


Does the '&evtMsg' also means 'ref evtMsg'? Thanks for helping me with
this. :)
 
P

Paul G. Tobey [eMVP]

You should have access to the Help for C++ programming on your target
device, no? API calls are well-documented in there, for the most part. The
ability to read C++ and create matching C# is just about critical to Smart
Device development.

That's the wrong code to start with, at least the way I read it. You have
to call QASetWindowsJournalHook(), not SetWindowsHook().

[DllImport("coredll.dll", SetLastError=true)]
public static extern UInt QASetWindowsJournalHook( int nFilterType,
HOOKPROC pfnFilterProc, ref EVENTMSG pfnEventMsg );

Now, you'll have to define HOOKPROC correctly so that it matches the
signature of the function delegate that you're going to pass it.

Don't forget to declare and call, at the appropriate time,
QAUnhookWindowsJournalHook(), too.

Paul T.
 
G

Guest

Well there are a few things to consider at this point:

1. Hooking is unsupported in CE, so while journaling works, there's no
guarantee it will continue to work.
2. Hooking is not trivial. It's complex and getting it wrong will render
the device inoperable without a restart
3. If you are intending to call native APIs like this, you really need to
understand how they work and be able to read C and convert it to C#. I did
get journal hooking working about a year ago and it took me a couple days to
get the kinks worked out.The odds that anyone on these groups is goign to
want to spend that kind of effort walking you through it, especially when
you're having difficulty even declaring the P/Invokes are probably not so
good. I'd recommend that you do some other P/Invoke work first to get a
feel for it. There are a lot of online articles, tutorials and samples for
a whole lot of stuff. Once you have a better handle on how the marshaler
works, then look at keyboard hooks - they're a bit simpler and IIRC Alex
Yakhnion blogged a fairly complete solution for them. Once you have that
working, then try journaling again and come back with more pointed questions
than the general "can you show me how to do this?" stuff.
 
T

techiechic

I tried QASetWindowsJournalHook and it returned hookId = 1, so that
means it must be working.
My HookCallback looks like this:

HookCallback(int nCode, IntPtr wParam, IntPtr lParam). Is this the
correct HookCallback?

When I converted lParam to EVENTMSG struct the result is:
message: between 512 - 514
lParam: 11534478 (random numbers) Do I have to convert it to another
structure?

Do you know the meaning of 512 - 514? Lastly, my application is super
slow, like when i click inside a textbox it takes sometime to get the
focus and it doesn't exit, I need to reset my device. Thanks.
 
G

Guest

There is no public documentation on what the EVENTMSG members mean. The
"random numbers" look a lot like handles. Maybe they're pointers to other
structs. Maybe they're window handles. I would assume that the meaning of
the message member could affect what they mean as well.

My bet that the fact it's slow is becasue you're not calling the next hook,
so they're piling up in your hook. Did I mention earlier that if you did
this wrong the device would become unusable and would have to be reset (see
point #2 in my last post)?
 
P

Paul G. Tobey [eMVP]

I've checked the GWES source code. The lparam parameter to the hook
callback does appear to be a pointer to the EVENTMSG structure that you
passed to the hooking function (so don't let that be deleted while you're
still using it!)

Yes, your application is going to be slower. You're seeing every single
message to every application before they go into any queue and, therefore,
you're causing all messages in the system to be serialized. You do also
have to CallNextHook in order to assure that the hooking stack is handled
correctly. It does work, although as I think we've said, it's not for
general use.

Paul T.
 
G

Guest

Oh fun, so you pass it in and it gets passed back filled out later. That
means that struct better be pinned or you're going to get all sorts of
non-reproduceable crashes in the field when you get GC compaction that moves
it.


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com



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

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