tallow Posted April 9, 2009 Share Posted April 9, 2009 Hi Guys I have a program that supports floating list boxes whenever i right click on screen i get a menu. one item in the list is very commonly used. I would like to create a script that would activate in the following way. When i right click, the mouse cursor would automatically jump the required number of pixels and auto left click the menu. I assume a hotkey would be needed in order to enable disable the function. Can anyone show me the way here. Thanks for any help in advance. Link to comment Share on other sites More sharing options...
Mat Posted April 9, 2009 Share Posted April 9, 2009 Is that anywhere on the screen or just the list box thing, sorry, what you want to do isn't the most specific. look at MouseGetPos and MouseMove MouseGetPos should return $array[0] = x and $array[1] = y you then need, mousemove with coords $array[0] + 10 and $array[1] - 20 (just an example). this moves the mouse relatively to the cursor position. however, I think you would be better off using the keyboard, as sometimes menu's can go up, rather than down, eg if your in the bottom corner. right click in your browser and press B (I use firefox, but it should be similar in other browsers). this will send you back. see if you can do the same with your menu, it should underline the key-letter. AutoIt Project Listing Link to comment Share on other sites More sharing options...
tallow Posted April 9, 2009 Author Share Posted April 9, 2009 Is that anywhere on the screen or just the list box thing, sorry, what you want to do isn't the most specific. look at MouseGetPos and MouseMove MouseGetPos should return $array[0] = x and $array[1] = y you then need, mousemove with coords $array[0] + 10 and $array[1] - 20 (just an example). this moves the mouse relatively to the cursor position. however, I think you would be better off using the keyboard, as sometimes menu's can go up, rather than down, eg if your in the bottom corner. right click in your browser and press B (I use firefox, but it should be similar in other browsers). this will send you back. see if you can do the same with your menu, it should underline the key-letter. When you right click anywhere on screen the same menu pops up So if i get you correctly you need to build a script around MouseGetPos upon right click so the script knows where the mouse is, then MouseMove the required number of pixels and MouseClick (left) voila one working script. I will have a go this evening and see if i can accomplish this. thanks for your help really appreciated. Incidentally your right about menu changing relative position to cursor when at extreme edges hadnt noticed if im honest before. However it wont effect me as i always approx centre of screen for this function. Link to comment Share on other sites More sharing options...
tallow Posted April 9, 2009 Author Share Posted April 9, 2009 Hi I have looked at various scripts to give me a clue and have come up with the following script. Yes theres a but it works but for one thing . the mouse cursor dissapears of to the top left handside of the screen instead of relative to the cursor. I assume i have done something wrong with regard to mousegetpos and mousemove. Any hints please greatfully received HotKeySet("{F4}", "StartProg") HotKeySet("{ESC}", "EndProg") ; Infinite loop While 1 Sleep(100) WEnd Func StartProg() MouseClick ("right") $pos = MouseGetPos() MouseMove(0, 50) Sleep (100) EndFunc Func EndProg() Exit EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 9, 2009 Moderators Share Posted April 9, 2009 tallow,Mouse coordinates are relative to the screen (unless you alter this using Opt(MouseCoordMode)). So you need to add your "move" pixels to the position of the mouse as it clicks. Try this:Func StartProg() MouseClick ("right") $pos = MouseGetPos() MouseMove($pos[0], $pos[1] + 50) Sleep (100) EndFuncM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
tallow Posted April 9, 2009 Author Share Posted April 9, 2009 tallow, Mouse coordinates are relative to the screen (unless you alter this using Opt(MouseCoordMode)). So you need to add your "move" pixels to the position of the mouse as it clicks. Try this:Func StartProg() MouseClick ("right") $pos = MouseGetPos() MouseMove($pos[0], $pos[1] + 50) Sleep (100) EndFunc M23 Thank you i was just putting that together when you replied I ended up with this and it works perfectly except for a misunderstanding on my part. I had assumed that the f4 hotkey would enable the script rather than run it I actually want to be able to enable disable the macro with say f4 so that when enabled any right click will run script and when disabled normal right click operation. Any clues on that one HotKeySet("{F4}", "StartProg") HotKeySet("{ESC}", "EndProg") ; Infinite loop While 1 WEnd Func StartProg() MouseClick ("right") $pos = MouseGetPos() MouseMove($pos[0] + 50, $pos[1] + 75) MouseClick ("left") EndFunc Func EndProg() Exit EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 9, 2009 Moderators Share Posted April 9, 2009 tallow,Great minds thinking alike, eh?In this script F4 now acts a toggle which, when set, hijacks the right mouseclick to run the "Special_Right_Click" code instead:expandcollapse popup#include <GUIConstantsEx.au3> #include <MouseSetOnEvent_UDF.au3> Global $fFunc_State = False, $fRunning = False HotKeySet("{F4}", "ToggleProg") HotKeySet("{ESC}", "EndProg") ; Infinite loop While 1 Sleep(100) ; <<<< very important or you use 100% CPU! WEnd Func Special_Right_Click() ; Only run it once per click If $fRunning = True Then Return $fRunning = True ; Do our "right click" thing! MouseClick("right") $pos = MouseGetPos() MouseMove($pos[0] + 50, $pos[1] + 75) MouseClick ("left") ; Reset the flag $fRunning = False EndFunc Func ToggleProg() ; Toggle the flag $fFunc_State = Not $fFunc_State ; If set, use our mouse function If $fFunc_State Then _MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT, "Special_Right_Click") Else _MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT); Renable normal mouse button EndIf EndFunc Func EndProg() Exit EndFuncYou will need to download the MouseSetOnEvent UDF from MrCreatoR which you can find here. The rest of the script is pretty self-explanatory (I hope!)I had fun with this. :-) Thanks for the problem - keeps the old grey cells active (and my mind off the mother-in-law's imminent arrival for Easter!).M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
tallow Posted April 10, 2009 Author Share Posted April 10, 2009 Wow thanks for that it all works perfectly We call ours outlaws by the way lol Is there a way to substitute the f4 key for either the back mouse button on my intellimouse or press middle button. Just a nice to have not essential. Thank you for all your help. I can see me spreading the word on scripting autoit style So powerfull. Happy holidays. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now