comp.lang.ada
 help / color / mirror / Atom feed
* simulate mouse click - windows
@ 2005-12-23  1:47 Gutek
  2005-12-23  2:51 ` Steve
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Gutek @ 2005-12-23  1:47 UTC (permalink / raw)


Hi,
I'm writing program for windows, which is going to communicate by RS232
with
my home-made device (functionally it is something like a mouse).
I'm using GNAT.
My program is listening the data coming from device, and according to
them
it has to:
1) Change cursor position
2) Simulate mouse clicks (left and right button)

I have solved the problem with changing cursor position - using
"GWindows"
from: http://www.gnavi.org (Set_Cursor_Position, Get_Cursor_Position
procedures).


But,
How could I simulate clicks?


Thanks in advice.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: simulate mouse click - windows
  2005-12-23  1:47 simulate mouse click - windows Gutek
@ 2005-12-23  2:51 ` Steve
  2005-12-23  6:07   ` tmoran
  2005-12-23 11:13 ` bubble
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Steve @ 2005-12-23  2:51 UTC (permalink / raw)


"Gutek" <gut@op.pl> wrote in message 
news:1135302476.367605.172030@g14g2000cwa.googlegroups.com...
> Hi,
> I'm writing program for windows, which is going to communicate by RS232
> with
> my home-made device (functionally it is something like a mouse).
> I'm using GNAT.
> My program is listening the data coming from device, and according to
> them
> it has to:
> 1) Change cursor position
> 2) Simulate mouse clicks (left and right button)
>
> I have solved the problem with changing cursor position - using
> "GWindows"
> from: http://www.gnavi.org (Set_Cursor_Position, Get_Cursor_Position
> procedures).
>
>
> But,
> How could I simulate clicks?
>
Do you just want to use this device with your program?  Or do you want it to 
act as the mouse for windows?

If the you want the device to appear as a mouse to window, you'll need to 
look into writing device drivers.

You may be able to find source code for existing mouse drivers on the net to 
get an idea of how its done.

I hope this helps.

Steve
(The Duck)

>
> Thanks in advice.
> 





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: simulate mouse click - windows
  2005-12-23  2:51 ` Steve
@ 2005-12-23  6:07   ` tmoran
  0 siblings, 0 replies; 7+ messages in thread
From: tmoran @ 2005-12-23  6:07 UTC (permalink / raw)


>> How could I simulate clicks?
>If the you want the device to appear as a mouse to window, you'll need to
>look into writing device drivers.
   That's surely the Right Way.  IIRC there's a function "mouse_event"
to which you can pass position and action.  There may be gotchas about

  type Mouse_Actions is new Dword;

  MOUSEEVENTF_MOVE       : constant Mouse_Actions := 16#0001#; -- mouse move
  MOUSEEVENTF_LEFTDOWN   : constant Mouse_Actions := 16#0002#; -- left button down
  MOUSEEVENTF_LEFTUP     : constant Mouse_Actions := 16#0004#; -- left button up
  MOUSEEVENTF_RIGHTDOWN  : constant Mouse_Actions := 16#0008#; -- right button down
  MOUSEEVENTF_RIGHTUP    : constant Mouse_Actions := 16#0010#; -- right button up
  MOUSEEVENTF_MIDDLEDOWN : constant Mouse_Actions := 16#0020#; -- middle button down
  MOUSEEVENTF_MIDDLEUP   : constant Mouse_Actions := 16#0040#; -- middle button up
  MOUSEEVENTF_WHEEL      : constant Mouse_Actions := 16#0800#; -- wheel button rolled
  MOUSEEVENTF_ABSOLUTE   : constant Mouse_Actions := 16#8000#; -- absolute move

  procedure mouse_event(Action : in Mouse_Actions;
                        Dx, Dy : in Dword;
                        Data   : in Dword;
                        Extra_Info : in Dword);
  pragma Import(StdCall, mouse_event, "mouse_event");

That may be obsolete, and I don't recall what the requirements are on
who owns what window,



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: simulate mouse click - windows
  2005-12-23  1:47 simulate mouse click - windows Gutek
  2005-12-23  2:51 ` Steve
@ 2005-12-23 11:13 ` bubble
  2005-12-23 12:47 ` Adrien Plisson
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: bubble @ 2005-12-23 11:13 UTC (permalink / raw)


"GetCapture"
"sendMessage"
should be work in window

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/mouseinput/aboutmouseinput.asp

"Gutek" <gut@op.pl> 
???????:1135302476.367605.172030@g14g2000cwa.googlegroups.com...
> Hi,
> I'm writing program for windows, which is going to communicate by RS232
> with
> my home-made device (functionally it is something like a mouse).
> I'm using GNAT.
> My program is listening the data coming from device, and according to
> them
> it has to:
> 1) Change cursor position
> 2) Simulate mouse clicks (left and right button)
>
> I have solved the problem with changing cursor position - using
> "GWindows"
> from: http://www.gnavi.org (Set_Cursor_Position, Get_Cursor_Position
> procedures).
>
>
> But,
> How could I simulate clicks?
>
>
> Thanks in advice.
> 





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: simulate mouse click - windows
  2005-12-23  1:47 simulate mouse click - windows Gutek
  2005-12-23  2:51 ` Steve
  2005-12-23 11:13 ` bubble
@ 2005-12-23 12:47 ` Adrien Plisson
  2005-12-24  1:54 ` Gutek
  2005-12-24  2:59 ` Stephen Leake
  4 siblings, 0 replies; 7+ messages in thread
From: Adrien Plisson @ 2005-12-23 12:47 UTC (permalink / raw)


Gutek wrote:
> Hi,
> I'm writing program for windows, which is going to communicate by RS232
> with
> my home-made device (functionally it is something like a mouse).
> I'm using GNAT.
> My program is listening the data coming from device, and according to
> them
> it has to:
> 1) Change cursor position
> 2) Simulate mouse clicks (left and right button)

as Steve pointed out, it all depends on your needs.

if you need this only for one specific application, you should try 
Windows' SendMessage function, and all of its counterparts 
(PostMessage...).
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues.asp>

if you need to take control of the whole system, you should try Hooks. 
the low-level mouse hook allows you to send system wide mouse messages, 
and the CBT (computer based training) hook allows you to send almost any 
message.
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks.asp>
beware that hooks are more powerfull but more difficult to use...

although the MSDN is targeted at C users, it should be easily transposed 
to Ada. I'm just not sure if all those functions are available in 
Win32Ada...

i once wrote a C application which automagically moved the mouse (a 
windows implementation of an old MacOS kind of virus which tends to 
drive the user crazy...) i can make the source code available sometime 
in January if you need it (i will be away until then).

have a merry christmas and happy new year.

-- 
rien



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: simulate mouse click - windows
  2005-12-23  1:47 simulate mouse click - windows Gutek
                   ` (2 preceding siblings ...)
  2005-12-23 12:47 ` Adrien Plisson
@ 2005-12-24  1:54 ` Gutek
  2005-12-24  2:59 ` Stephen Leake
  4 siblings, 0 replies; 7+ messages in thread
From: Gutek @ 2005-12-24  1:54 UTC (permalink / raw)


Hi,
I have found the solution with your help:

Most of widnows API functions are implemented in win32-xxx.adb modules,
which were binded to GNAT.
Simulating mouse clicks and movement were very easy with them :)

-- (...)

with Win32.Winuser;

-- (...)
-- click:

Win32.Winuser.Mouse_Event(Win32.Winuser.Mouseeventf_Leftdown,0,0,0,0);
Win32.Winuser.Mouse_Event(Win32.Winuser.Mouseeventf_Leftup,0,0,0,0);

-- (...)
-- mouse movement:

Win32.Winuser.Mouse_Event(Win32.Winuser.Mouseeventf_Move,20,20,0,0);

---:/~




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: simulate mouse click - windows
  2005-12-23  1:47 simulate mouse click - windows Gutek
                   ` (3 preceding siblings ...)
  2005-12-24  1:54 ` Gutek
@ 2005-12-24  2:59 ` Stephen Leake
  4 siblings, 0 replies; 7+ messages in thread
From: Stephen Leake @ 2005-12-24  2:59 UTC (permalink / raw)


"Gutek" <gut@op.pl> writes:

> Hi,
> I'm writing program for windows, which is going to communicate by RS232
> with
> my home-made device (functionally it is something like a mouse).
> I'm using GNAT.
> My program is listening the data coming from device, and according to
> them
> it has to:
> 1) Change cursor position
> 2) Simulate mouse clicks (left and right button)
>
> I have solved the problem with changing cursor position - using
> "GWindows"
> from: http://www.gnavi.org (Set_Cursor_Position, Get_Cursor_Position
> procedures).

In the CVS version of GWindows, there is a package
GWindows.Testing.Events, that has a nice binding to Mouse_Event. That
will let you generate mouse events on the normal Windows event queue,
just like a real mouse.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-12-24  2:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-23  1:47 simulate mouse click - windows Gutek
2005-12-23  2:51 ` Steve
2005-12-23  6:07   ` tmoran
2005-12-23 11:13 ` bubble
2005-12-23 12:47 ` Adrien Plisson
2005-12-24  1:54 ` Gutek
2005-12-24  2:59 ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox