1

Thema: Mouse positioning scripts

Dear all

one of the most commonly used type of advanced script with DNS is mouse positioning scripts e.g. the following script clicks the mouse at a certain position in your application.

SetMousePosition 1,234,494
Wait 0.1
ButtonClick 1,1

To create such a script it is necessary to work out the coordinates of the particular point where you want to click the mouse and then call up the command editor and insert the necessary code. Thus it can take a few minutes to create such a script and it can be awkward to work out the mouse position coordinates. However the script below will do all the hard work for you, all you do is position the mouse on the application window where you would like the mouse click to occur and call the advanced script containing the following code e.g.

"add mouse position script"

Option Explicit
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Type POINTAPI
x As Long
y As Long
End Type
Declare Function GetCursorPos Lib "user32" _
Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Declare Function GetWindowRect Lib "user32" _
Alias "GetWindowRect" (ByVal hwnd As Long, _
lpRect As RECT) As Long
Declare Function GetForegroundWindow& Lib "user32" ()
Function GetWinCurPos(hwnd As Long) As POINTAPI
Dim pt As POINTAPI
Dim wRect As RECT
Dim result As POINTAPI
Dim EngineControl As DgnEngineControl
GetCursorPos pt
GetWindowRect hwnd, wRect
result.x = pt.x - wRect.Left
result.y = pt.y - wRect.Top
GetWinCurPos = result
End Function
Sub Main
Dim hwnd As Long
Dim result As POINTAPI
Dim clip As String
hwnd = GetForegroundWindow
result = GetWinCurPos(hwnd)
clip = "SetMousePosition 1," & result.x & _
"," & result.y
EngineControl.DlgShow(dgndlgNewCommandWizard, 0, , 0)
Wait 0.4
SendKeys"%y"
Wait 0.2
SendKeys"{Down 3}{Tab 2}"
Wait 0.2
SendKeys clip
Wait 0.1
SendKeys"~Wait 0.2~ButtonClick 1, 1"
Wait 0.1
'SendKeys"%a"
'The previous line will work in the English version, the one below in German

SendKeys "%z"
Wait 0.1
'SendKeys"%c"
'See above

SendKeys "%n"
End Sub

After calling the above script your new script will be created automatically and all you need to do is give it a name, after that you can call it any time you like while using the relevant application.

Lindsay

2

Re: Mouse positioning scripts

Rüdiger

thanks for pointing out the difference accelerator keys that are used with German, I guess I should check these out as I am posting on a German forum, apologies to anyone wasting time with the script with the wrong accelerator keys.

Lindsay

3

Re: Mouse positioning scripts

Hello together,

Lindsay, thanks for this useful mouse position script.

I am looking for a simular script for the right mouse click. (like ButtonClick 2, 1)

I would like to start a programm from the taskbar with a right mouse click on a specific icon.
The second step is to click on a different position above the first one.
But the position inside the taskbar of the icon is not always the same.

I would like to use a script for starting this programm.

If anyone have an idea how to find the postion or how to start a programm from the taskbar with a rightclick please let me know.

Kind regards

Jörg


Hallo zusammen,

vielen Dank an Lindsay für dieses hilfreiche Skript.

Ich suche ein ähnliches Skript für die rechte Maustaste (wie ButtonClick 2, 1).

Ich möchte ein Programm aus der Taskleiste mit einem Rechtsklick auf ein bestimmtes Icon starten. Im zweiten Schritt muss ich auf dem erscheinenden Menü mit der linken Maustaste auf "Umschalten zu Messbetrieb" klicken.
Leider befindet sich das Icon nicht immer an der selben Stelle.

Dies würde ich gerne per Skript machen.

Wenn jemand mir hierbei helfen könnte wäre ich sehr dankbar.

Gruß

Jörg

http://img94.imageshack.us/img94/9307/umschaltenmessbetrieb.jpg

Uploaded with ImageShack.us

Beitrags-Anhänge

Umschalten_Messbetrieb.JPG 17.34 kb, 1 Downloads seit 2010-06-18 

Sie haben nicht die Berechtigung, um diese Datei herunterzuladen.

4

Re: Mouse positioning scripts

Jörg

Try this, obviously you can shorten the name of the command if you wish, currently you would say e.g.

"right click system tray 1"
"right click system tray 4"
etc

the list just contains the numerals 1 to 20

Lindsay

I have additionally attached the code below to copy and paste.

EDIT: Unfortunately the Google translation into German will mess up the actual code for copying, so if in doubt you will just have to copy the code from the screenshot.

http://img691.imageshack.us/img691/807/rightclicksystemtrayico.jpg

Declare Function SetForegroundWindow Lib "user32" _
Alias "SetForegroundWindow" (ByVal Hwnd As Long)As Long
Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Declare Function FindWindowEx Lib "user32" Alias _
"FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Sub main
Dim h1, h2, h3 As Long
'Get the taskbar window
h1 = FindWindow("Shell_TrayWnd","")
h2 = FindWindowEx(h1,0,"TrayNotifyWnd","")
SetForegroundWindow(h2)
Wait 0.2
SendKeys"{Left "+ListVar1+"}{Left}+{F10}",True
' to then choose an item on the menu just moved down
' the relevant amount of times, e.g. for the top item
SendKeys"{Down}"
' optionally add the enter key to select the menu item
End Sub

5

Re: Mouse positioning scripts

Hello Lindsay,

thanks a lot. The scripts works very well for starting a program from the taskbar with a rightclick.

It is possible to extend this makro in a way that the macro will save the name (not the position) of the program with was choosen from the taskbar like your first mouse position script? This would be usefull for using the result for a different macro.   
The position changes from time to time, depending what programs are running.

I would like to start a program (in this specific case an IP-changer) from the taskbar with a command like "switch IP" without knowing the position of the Icon all the time.

Kind regards

Jörg

6

Re: Mouse positioning scripts

Jörg

it would require a script to manually check the names of all the system tray icons and log the position of the relevant one (IP Switcher), it's not so easy to do that unfortunately with advanced scripting and like you say the previous script I gave you will do this but you need to know which position in the system tray that the IP Switcher icon is. Before even considering an advanced script I would look at another way (e.g. commandline function) for getting IP Switcher to do what you want to do without going via the system today. Can you point me to download of the particular IP Switcher software that you are using as there may be a simpler way to do this.

Edit: I meant to say that I realised that you want to use this principle and script for doing similar things with other applications as well. However one of the difficulties of that is that different application developers use different parameters within the application code to store the relevant application name. I looked at this problem quite a few years ago as I wanted to do this with Skype (and other applications) but the compromise I ended up with was using the script above.

Lindsay

7

Re: Mouse positioning scripts

monkey8 schrieb:

Jörg

Before even considering an advanced script I would look at another way (e.g. commandline function) for getting IP Switcher to do what you want to do without going via the system today. Can you point me to download of the particular IP Switcher software that you are using as there may be a simpler way to do this.

Lindsay

Hello Lindsay,

I  tried already the way with commandline function, but the program does not support this feature (feedback from my company IT). Unfortunately I have no possibility to give you any information about this program. This program is developed for my company and it works closely with the firewall.

I guess I have to use the script above. Thanks for your support.

Kind regards

Jörg

8

Re: Mouse positioning scripts

Hello Jörg

If your program was created in-house can you not get the developers to make the particular function you want to access more accessible (e.g. with a hot key assignment)?

The only other option I can see of finding it directly on the system tray is if you download a program such as WinID (which is free and very small), start it up, and then position your mouse over the different system tray icons. If the system tray icon that you need to access the context menu for has a title then we might be able to do it. If you try this you will notice that the class name for all the system tray icons is "SysPager". However most developers usually leave the title field blank and thus I can't distinguish between them using an advanced script. If your particular system tray icon does have a title then we might possibly be able to do something.

if you Google "download WinID" you will find various places to download it.

Best wishes

Lindsay

9

Re: Mouse positioning scripts

Hello Lindsay,

thanks for the advise to download WinID.

Unfortunately it is not allowed to use this programm in order of IT regulations. I am working in a huge company with high security rules.
I have checked this on my privat computer with other applications. But the title fields are always blank.

The ip-switcher-program was developed ouside the company. There is no easy way to ask for additional features.

Kind regards

Jörg

10

Re: Mouse positioning scripts

Hello Jörg,

If your company allows, Vista Switcher is a very nice replacement for the Windows Alt+Tab function. Check out the following URL for an explanation.  It is also freeware.

http://www.ntwind.com/software/vistaswitcher.html

review of the tool:

http://download.cnet.com/Switcher/3000- … 65605.html

I am not affiliated with the company that created this tool.  I recently stumbled upon a review, and have been happily using the tool ever since.  I have created a couple of scripts to launch this software a couple of different ways.

I like the way the software shows a smaller screen print of the application, allowing you to visually see what you can then select.  See the attachment.

Bruce

Beitrags-Anhänge

Clipboard01.jpg 126.71 kb, 1 Downloads seit 2010-07-15 

Sie haben nicht die Berechtigung, um diese Datei herunterzuladen.

11

Re: Mouse positioning scripts

Hello forum, hello Lindsay!
This script is really great!  I’ve tried that today at work and it worked fine!  Thanks a lot for sharing this!

12 Zuletzt bearbeitet von Stecknadel (15.06.2011 20:30:45)

Re: Mouse positioning scripts

Hello forum, hello Lindsay!
Today I had some problems with the mouse positioning script.  It only worked in 50% of the time.  I regularly got the error message:”Die Koordinaten befinden sich außerhalb des Bereichs“ which I think means in English something like “the coordinates are outside of the area”.  This error occurred regularly when I tried to access the taskbar with a mouse positioning script.  It didn’t appear when I tried to access other areas on the screen.  Unfortunately this error message can’t be closed by voice, neither by the keyboard.  I have to use the mouse for closing this error message, and that’s really bad for my RSI
Do you have any idea, why this error message appears?  Did I do anything wrong?  Or does the mouse positioning script just not work for the taskbar?
Thank you very much in advance!
Susanne

13

Re: Mouse positioning scripts

Hi Susanne

Glad you liked the script, it's very popular and saves a lot of time.  The script was really written to produce application-specific scripts to position the mouse on a particular application window.  If you want to use it for positioning the mouse on the taskbar menu can still do it but you need to follow the following procedure:

1 before calling the script click on the desktop background e.g. the desktop wallpaper
2.  Position the mouse on the taskbar where ever you want it to click and then call the command
3.  Give it a name as usual and then change it from "Application-specific" to "Global"
4.  Finally you need to change one digit on the line SetMousePosition, you need to change the "1" to "0" e.g.

SetMousePosition 1, 457, 678

becomes

SetMousePosition 0, 457, 678

This then positions the mouse relative to the top left hand corner of the screen as opposed to the top left-hand corner of the specific window.  Changing it from "Application Specific" to "Global" means you can call it at any time and therefore access the taskbar.

Now you could if you want just have a different script for taskbar and desktop commands where instead of having to change it from application-specific to global you can make the script do this and also you can make the script change the 1 to 0.  You can then call the command something like "add taskbar position command".

Lindsay
www.pcbyvoice.com

14

Re: Mouse positioning scripts

Hello Lindsay,
Thank you very much for your help!  I tried this today at work and it worked fine!  Now I can easily access the taskbar, that's so great! 
But unfortunately there is still a little problem: sometimes the mouse positioning script does not work.  Occasionally it produces an empty script like that:
" Sub main

end sub"

Then I have to work out the coordinates manually.  That's no big deal, but do you know, what's in this could be?
I just used the script that you posted above.  And sometimes it works fine, and sometimes not. I recognized that I always used coordinates near the edge of the screen, when the script didn't work.  Near the middle of the screen it always worked fine.  I have a 24 inch monitor if that makes a difference...
Thank you very much in advance!!

15

Re: Mouse positioning scripts

Hi Susanne

just add 0.2 to every single Wait time on the bottom half of the script e.g.

Wait 0.4

becomes

Wait 0.6

it will slow it down a little but will make it more reliable.  In fact to be even safer set the first one after calling the dialogue with the engine control to something like 0.8 initially.  You can always then speed it up once you get it working reliably.  It's the one thing with Advanced Scripting that I don't like, using Wait states but it just makes it easier than alternative methods.

Best wishes
Lindsay
www.pcbyvoice.com

16

Re: Mouse positioning scripts

Hello Lindsay!
Thank you very much for your help!!  I tried this today at work, but unfortunately it didn't work:-( I tried many different waiting times.  At the end I had 5.0 as waiting time at each point and the script still didn't work.  It only worked at coordinates near the middle of the screen...  That's a really strange, isn't it? 
And even in the middle of the screen the script produced strange results, for example:
Sub Main
        SetMousePosition 1,-37,585
        Wait 0.2
        ButtonClick 1, 1
End Sub

I mean, -37 can't be a correct x-coordinate near the middle of the screen, can it...?
Do you have any idea what this could be? I don't understand that... :-(   
Thank you so much in advance!

17

Re: Mouse positioning scripts

Hi Susanne

the script will work pretty flawlessly but perhaps I have not explained exactly under what circumstances.  It is constructed to work relevant to the current application window.  Therefore if you want to position the mouse on a particular application and then click it then that application must be the active window at the time.  It obviously was not the case because that is the only way you can get negative numbers.

Just to add to that, if you are trying to click on your screen anywhere on the desktop, or on the taskbar then you will need to make sure that you actually click anywhere on the desktop or taskbar first before calling the script and then changing the SetMousePosition 1 to 0.

The only other time I have seen problems with the mouse coordinates is if you are using an exceptionally high DPI (e.g. above 125%) and not using Windows XP style scaling.  You can check this by right clicking on your desktop (with Windows 7 and Windows Vista) and then choose Personalise, Display and check what your text size is set to.  If you have a custom text size and make sure it is set to use Windows XP type DPI scaling.

Let me know if that makes more sense and what the reading is for your text size.

Lindsay
www.pcbyvoice.com

18

Re: Mouse positioning scripts

Hello Lindsay,
Thank you very much for your help!  Now I know why the script doesn't work.  I use 125 % DPI and an extra large font.  I think that is the problem.  But unfortunately I can't switch to a lower DPI because I'm not only suffering from RSI but from office eye syndrom, too;-) so I have to use a high DPI To go easy on my poor dry eyes.  If I use too small fonts, my eyes get sore really fast...
But that's no big deal, so I have to discover the coordinates manually when they are not near the middle of the screen.  I have to do this just once.  When I have all my mouse positioning scripts done I won't have to waste my time with manually coordinates discovering;-))So that's no problem:-)
BTW Have you heard from Max yet?  I have written to him a week ago but haven't got an answer yet:-( and I'm really missing show numbers plus at work:-((

19

Re: Mouse positioning scripts

Oldies but goldies.

Lindsays Skript hat mir wieder mal den .... gerettet - weil Adobe es leider nicht erlaubt, in Adobe Acrobat (XI) einen Shortcut für die Funktion "Notiz zum Text hinzufügen" zu definieren, der sich mit einem Sprachbefehl aufrufen ließe.

Mit Lindsays Skript ließ sich sehr einfach ein Sprachbefehl zum Klick auf eine in die Werkzeugleiste eingefügte Symbolschaltfläche erzeugen (egal, wie groß das Acrobat-Fenster gerade ist), so dass jetzt das Kommando "Kommentar einfügen" fast so gut funktioniert wie in Word.

Daher war dieser Thread es wert, mal wieder nach oben geholt zu werden.

Thanks again, Lindsay!

Dragon Legal Group 15, Win 10 Pro, Office 2013/2016, SpeechMike Premium, i7-3770, 32 GB RAM, 240 GB SSD
Dragon für Mac 6.0.7, Office für Mac 2016, iMac Retina 5K Late 2015 4,0 GHz i7-6700K, 32 GB RAM, 1TB SSD

20

Re: Mouse positioning scripts

Meinhard schrieb:

- weil Adobe es leider nicht erlaubt, in Adobe Acrobat (XI) einen Shortcut für die Funktion "Notiz zum Text hinzufügen" zu definieren, der sich mit einem Sprachbefehl aufrufen ließe.

Die Kombination Strg+6 tut's nicht? Ich fand sie im Im Reader DC.
Gruß, Pascal

21

Re: Mouse positioning scripts

P.Roch schrieb:

Die Kombination Strg+6 tut's nicht? Ich fand sie im Im Reader DC.

Nein, lieber Pascal, die löst eine andere Funktion aus. Sie setzt eine Notiz irgendwohin (an die Mausposition). Für die von mir benötigte Funktion "Notiz zu Text hinzufügen", die eine markierte Textstelle hervorhebt und ein Notizenfenster damit verbindet (so dass der Leser weiß, worauf genau sich die Notiz bezieht), gibt es keinen nativen Shortcut in Acrobat.

Dragon Legal Group 15, Win 10 Pro, Office 2013/2016, SpeechMike Premium, i7-3770, 32 GB RAM, 240 GB SSD
Dragon für Mac 6.0.7, Office für Mac 2016, iMac Retina 5K Late 2015 4,0 GHz i7-6700K, 32 GB RAM, 1TB SSD