LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simulate pressing mouse button

How can I simulate pressing the left mouse button in Labview 6.0.2, on Windows 98

I want to create a tutorial option within my program.

When activated, the mouse will programatically move and press buttons within my application. At the same time a dialogue box will pop-up teaching the user how to use this program.

I have found examples showing how to programatically set the position of the mouse cursor - but no information on how to simulate pressing the mouse button.

Before anyone suggests any other solution - I cannot use local variables for the boolean switches because the mechanical action is latch not switch, and I cannot link the solution to key presses because the software is operated from a touch screen with a virtual
keyboard.

Any help would be greatly appreciated.
0 Kudos
Message 1 of 13
(7,695 Views)
Download G Toolbox:

http://www.geocities.com/gzou999/dl/GT21Demo.zip



mnewett@blueyonder.co.uk wrote:
> How can I simulate pressing the left mouse button in Labview 6.0.2, on
> Windows 98
>
> I want to create a tutorial option within my program.
>
> When activated, the mouse will programatically move and press buttons
> within my application. At the same time a dialogue box will pop-up
> teaching the user how to use this program.
>
> I have found examples showing how to programatically set the position
> of the mouse cursor - but no information on how to simulate pressing
> the mouse button.
>
> Before anyone suggests any other solution - I cannot use local
> variables for the boolean switches because the mechanical action is
> latch not switch, and I cannot l
ink the solution to key presses
> because the software is operated from a touch screen with a virtual
> keyboard.
>
> Any help would be greatly appreciated.
0 Kudos
Message 2 of 13
(7,695 Views)
Thanks for the reply, but I am already aware of G-toolbox.

I want to use the WIN32API functions to simulate the mouse click. I know that I have to use the mouse_event function - but as yet have not got it to work. Any help would be appreciated.

Regards

Mike
0 Kudos
Message 3 of 13
(7,695 Views)
Hi,

Actually, you have to use the SendInput API. mouse_event and keybd_event are
easier.

Any reason why you don't want to use the G toolbox? What you want to do is a
standard example..

What exactly didn't work when you tried it?

Regards,

Wiebe.

"mnewett@blueyonder.co.uk" wrote in message
news:50650000000500000050DE0000-1042324653000@exchange.ni.com...
> Thanks for the reply, but I am already aware of G-toolbox.
>
> I want to use the WIN32API functions to simulate the mouse click. I
> know that I have to use the mouse_event function - but as yet have not
> got it to work. Any help would be appreciated.
>
> Regards
>
> Mike
0 Kudos
Message 4 of 13
(7,702 Views)
thanks for reply - I didnt have any problems with G-toolbox. I downloaded the demo and was very impressed.

However, I would like to learn more about the WIN32API functions myself.

A) I may come across an application where I want to use a function that is not covered by G-toolbox, and B) More importantly, I still use Labview 4.0 on occassion - there is no support for this with G-toolbox.

Its a shame G-toolbox demo does not allow you to see the block diagram of the simulate click demo.

I was unclear by your reply whether I should be using SendInput or mouse_event function. Can you offer any more help ?

Regards

Mike
0 Kudos
Message 5 of 13
(7,702 Views)
Hi,

The prototype for the mouse_event api is:

VOID mouse_event(
DWORD dwFlags, // motion and click options
DWORD dx, // horizontal position or change
DWORD dy, // vertical position or change
DWORD dwData, // wheel movement
ULONG_PTR dwExtraInfo // application-defined information
);

For an example, set dwflags to MOUSEEVENTF_LEFTDOWN (2), and the rest to
zero. This simulates a button down. Follow this by the same structure, but
use MOUSEEVENTF_LEFTUP (4).

These variables come from the SDK. You should download it (if yuo did not
already), to understand all this.

Put it in a loop, with a timer interval, and you'll notice that every time
the code executes, a left mouse bu
tton up and down is generated. (test by
hovering over a button)

From the Microsoft Platform SDK : Windows NT/2000/XP: This function has been
superseded. Use SendInput instead.

This function is a lot more complicated. The mouse_event will work for (at
least) the next few operating systems.

Regards,

Wiebe.


"mnewett@blueyonder.co.uk" wrote in message
news:5065000000050000005EDE0000-1042324653000@exchange.ni.com...
> thanks for reply - I didnt have any problems with G-toolbox. I
> downloaded the demo and was very impressed.
>
> However, I would like to learn more about the WIN32API functions
> myself.
>
> A) I may come across an application where I want to use a function
> that is not covered by G-toolbox, and B) More importantly, I still use
> Labview 4.0 on occassion - there is no support for this with
> G-toolbox.
>
> Its a shame G-toolbox demo does not allow you to see the block diagram
> of the simulate click demo.
>
> I was unclear by your reply whether I should be
using SendInput or
> mouse_event function. Can you offer any more help ?
>
> Regards
>
> Mike
0 Kudos
Message 6 of 13
(7,702 Views)
You beauty - thanks very much for help. Got it working now. Wasn't putting 2 and 4 in for mouseevenft_leftup / down. Was using 0 and 1.

Where do you find info on what values to put in?

Anyway - thanks very much.

Regards

Mike
0 Kudos
Message 7 of 13
(7,702 Views)
Mike,

It's all in the MS SDK. Well, the problem is that the sdk only uses the
constant names. This is because it expects the users to use a programming
language that uses header files.

The following is copied from one of those header files:

MOUSEEVENTF_MOVE equ 1h
MOUSEEVENTF_LEFTDOWN equ 2h
MOUSEEVENTF_LEFTUP equ 4h
MOUSEEVENTF_RIGHTDOWN equ 8h
MOUSEEVENTF_RIGHTUP equ 10h
MOUSEEVENTF_MIDDLEDOWN equ 20h
MOUSEEVENTF_MIDDLEUP equ 40h
MOUSEEVENTF_WHEEL equ 800h
MOUSEEVENTF_ABSOLUTE equ 8000h

The values can be or-ed. E.g. A relative move is 1, an absolute move is 1 O
R
8000h, is 8001h.

There are some (2, I think) new ones for XP, but I don't have them. The are
also used to simulate mouse key presses.

Regards,

Wiebe.


"mnewett@blueyonder.co.uk" wrote in message
news:50650000000500000073DE0000-1042324653000@exchange.ni.com...
> You beauty - thanks very much for help. Got it working now. Wasn't
> putting 2 and 4 in for mouseevenft_leftup / down. Was using 0 and 1.
>
> Where do you find info on what values to put in?
>
> Anyway - thanks very much.
>
> Regards
>
> Mike
0 Kudos
Message 8 of 13
(7,702 Views)
Thanks for you help.

I have another querry that you may be able to help me with.

I have now got the following working:
get the position of the mouse cursor in any window (GetCursorPos)
get the position of the mouse buttons in any window (GetAsyncKeyState - GetKeyboardState would only work in the labview window ?)
simulate the movement of the mouse (SetCursorPos)
simulate mouse clicks (mouse_event)

I am having problems with getting keyboard and simulating keyboard events.

The GetKeyboard State allows me to get the state of all the virtual keys in the open labview window only.

I believe that I have to use the SetWindowsHookExA (WH_Keyboard,b,c,d) command if I want to get
keystates if the Labview window is not open

It is the arguements b,d & d that I do not understand.

Also - what do I do once I have the hook working ? How do I then retrieve the keyboard state ?

Any help would be greatly appreciated

Regards

Mike




I
0 Kudos
Message 9 of 13
(7,702 Views)
Mike,

Using the SetWindowsHookEx function is not easy from LabVIEW (I never use
impossible...).

The function expects a pointer to a routine. In text based languages, you
can just use "pointer = OFFSET function" or something alike. In LabVIEW, the
only way I found of doing this, is by making a LabVIEW dll, and using the
LoadLibrary and GetProcAddress functions. This way you can build a function
in the dll to work like a keyboardhook proc, and get an adress (pointer) to
this function.

This is not easy at all. I got it working, but it works only for LabVIEW
application. I used the WH_KEYBOARD constant, maybe the WH_KEYBOARD_LL
constant works, but I don't seem to have it (I've old header fi
les...).

Regards,

Wiebe.

"mnewett@blueyonder.co.uk" wrote in message
news:506500000005000000D6E50000-1042324653000@exchange.ni.com...
> Thanks for you help.
>
> I have another querry that you may be able to help me with.
>
> I have now got the following working:
> get the position of the mouse cursor in any window (GetCursorPos)
> get the position of the mouse buttons in any window (GetAsyncKeyState
> - GetKeyboardState would only work in the labview window ?)
> simulate the movement of the mouse (SetCursorPos)
> simulate mouse clicks (mouse_event)
>
> I am having problems with getting keyboard and simulating keyboard
> events.
>
> The GetKeyboard State allows me to get the state of all the virtual
> keys in the open labview window only.
>
> I believe that I have to use the SetWindowsHookExA (WH_Keyboard,b,c,d)
> command if I want to get keystates if the Labview window is not open
>
> It is the arguements b,d & d that I do not understand.
>
> Also - what do I do once I
have the hook working ? How do I then
> retrieve the keyboard state ?
>
> Any help would be greatly appreciated
>
> Regards
>
> Mike
>
>
>
>
> I
0 Kudos
Message 10 of 13
(7,702 Views)