Chain mouse click macros

If you have macros or EventGhost Configuration Tree items you wish to share this is the place to do it.
Post Reply
dan Edens
Posts: 16
Joined: Mon Sep 24, 2018 7:57 pm

Chain mouse click macros

Post by dan Edens » Sun Apr 07, 2019 11:16 pm

So this is a tool I created a while ago to help with Chaining mouse click macros.

It's simple but it's crazy fast once you get it down.
I apologize for not making it 100% use ready I know it's pretty ugly, so let me have it lol.

Couple other things I just haven't fixed yet:
All the unnecessary global variables, (There is some reason, but not without the rest of the tree.)
Not pathing the log file to user.

In it's full set up, It chains together with another tool that lets mouse click macro's run while I'm using my mouse on a different screen by waiting and returning when my physical mouse moves. It lets me build in wait times if i need, and another one that records a couple other things as i go.

I use this to automate my client website checks and make click-to-than-screenshot macros (using boxcutter, a command line screenshot tool)


First is the python script that does the work, I included the Pastable version so you get the "Long Press - Simple clipout" part. which gives you just the coordinates.


Cheers

Code: Select all

import win32api
eg.globals.h_x = 1
eg.globals.h_y = 1
def mPos(x, y):
    win32api.SetCursorPos((x, y))
def start():
    eg.globals.h_x, eg.globals.h_y = win32api.GetCursorPos() #This works fine.
    print "Mouse was at " + str(eg.globals.h_x) + ", " + str(eg.globals.h_y) #This also displays normally.    
    return eg.globals.h_x, eg.globals.h_y
eg.globals.h_x, eg.globals.h_y = start()
eg.globals.xtemp = eg.globals.h_x
eg.globals.ytemp = eg.globals.h_y
eg.plugins.FileOperations.Write(2, u'{eg.globals.h_x},{eg.globals.h_y}', u'C:\\Users\\John.Edens\\Google Drive\\Join Files\\Stack\\Ghost files\\cords.txt', 2, 0, False, False, False, 'cp1252')
var1 = """eg.plugins.Mouse.MoveAbsolute({eg.globals.h_x},{eg.globals.h_y}, 2, False, True)
eg.plugins.EventGhost.Wait(.2)
eg.plugins.Mouse.LeftDoubleClick()
#eg.plugins.Mouse.LeftButton()
eg.plugins.EventGhost.Wait(.5)
"""
eg.plugins.System.SetClipboard(var1)
eg.plugins.Window.SendKeys(u'{Backspace}', False, 2)

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="WIP-2019.03.10-20.11.47">
    <Folder Name="Mouse click tool." XML_Guid="{0387646E-F931-4D77-B805-36B9AE9653FB}" Expanded="True">
        <Macro Name="Save and display mouse cords" XML_Guid="{EACB8DD5-EE38-43D6-B03C-D182BB850C56}" Expanded="True">
            <Event Name="Keyboard.Ctrl+Oem3" XML_Guid="{4E79E518-76FE-4755-9A0A-9DDDCD8A4383}" />
            <Action XML_Guid="{47058FB6-58C6-4B0B-9F90-C748856871A0}">
                EventGhost.JumpIfLongPress(1.0, XmlIdLink(1018))
            </Action>
            <Action Name="Set Mouse coords as H_x,H_y" XML_Guid="{1B437B65-3FEC-453A-B292-B7517ECCDF9C}">
                EventGhost.PythonScript(u'import win32api\neg.globals.h_x = 1\neg.globals.h_y = 1\ndef mPos(x, y):\n    win32api.SetCursorPos((x, y))\ndef start():\n    eg.globals.h_x, eg.globals.h_y = win32api.GetCursorPos() #This works fine.\n    print "Mouse was at " + str(eg.globals.h_x) + ", " + str(eg.globals.h_y) #This also displays normally.    \n    return eg.globals.h_x, eg.globals.h_y\neg.globals.h_x, eg.globals.h_y = start()\neg.globals.xtemp = eg.globals.h_x\neg.globals.ytemp = eg.globals.h_y\neg.plugins.FileOperations.Write(2, u\'{eg.globals.h_x},{eg.globals.h_y}\', u\'C:\\\\Users\\\\John.Edens\\\\Google Drive\\\\Join Files\\\\Stack\\\\Ghost files\\\\cords.txt\', 2, 0, False, False, False, \'cp1252\')\nvar1 = """eg.plugins.Mouse.MoveAbsolute({eg.globals.h_x},{eg.globals.h_y}, 2, False, True)\neg.plugins.EventGhost.Wait(.2)\neg.plugins.Mouse.LeftDoubleClick()\n#eg.plugins.Mouse.LeftButton()\neg.plugins.EventGhost.Wait(.5)\n"""\neg.plugins.System.SetClipboard(var1)\neg.plugins.Window.SendKeys(u\'{Backspace}\', False, 2)')
            </Action>
        </Macro>
        <Macro Name="Save and display mouse cords Basic" id="1018" XML_Guid="{EACB8DD5-EE38-43D6-B03C-D182BB850C56}" Expanded="True">
            <Action Name="Set Mouse coords as H_x,H_y" XML_Guid="{1B437B65-3FEC-453A-B292-B7517ECCDF9C}">
                EventGhost.PythonScript(u'import win32api\n#declaring x and y\neg.globals.h_x = 1\neg.globals.h_y = 1\ndef mPos(x, y):\n    win32api.SetCursorPos((x, y))\ndef start():\n    eg.globals.h_x, eg.globals.h_y = win32api.GetCursorPos() #This works fine.\n    print "Mouse was at " + str(eg.globals.h_x) + ", " + str(eg.globals.h_y) #This also displays normally.\n    return eg.globals.h_x, eg.globals.h_y\neg.globals.xtemp = eg.globals.h_x\neg.globals.ytemp = eg.globals.h_y\neg.globals.h_x, eg.globals.h_y = start()\neg.plugins.FileOperations.Write(2, u\'{eg.globals.h_x},{eg.globals.h_y}\', u\'C:\\\\Users\\\\John.Edens\\\\Google Drive\\\\Join Files\\\\Stack\\\\Ghost files\\\\cords.txt\', 2, 0, False, False, False, \'cp1252\')\neg.plugins.System.SetClipboard(u\'{eg.globals.h_x},{eg.globals.h_y}\')')
            </Action>
        </Macro>
    </Folder>
</EventGhost>

User avatar
kgschlosser
Site Admin
Posts: 4620
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Chain mouse click macros

Post by kgschlosser » Mon Apr 08, 2019 2:28 am

I wanted to comment on this..

you do not need to store everything into eg.globals. the only need for doing that is if you need to share data between 2 different marcos.

Here would be an example. using a remote to power off devices. if you device only has a toggle power command and not a turn on or turn off command then you do not want to be sending a command to it in the hopes it will turn off if it is already off. LOL not going to work.

so by storing the state that gets reported to EG you are able to know that if you press the power off button on a remote to turn off say a TV and AVR and a DVD player. it is going to power off the items correctly. if the state is already off then no command will need to be sent. and if it is on then it will need to send it.

so the eg.globals is best used for "shared" data between macros.

another thing would be for you to save the fingers all of the effort of typing the eg.plugins. over and over again.

Code: Select all

plg = eg.plugins

print plg.EventGhost.plugin.__class__.__name__
print plg.Window.plugin.__class__.__name__
print plg.Mouse.plugin.__class__.__name__
if a "." is in an object name then that means it is in object inside of an object. you can have an object name that has 5 or 6 + dots in it. who wants to keep on keying that over and over again. those kinds of objects are mutable. meaning then if you place it into a variable it is not a copy of the original. it is the original. so any changes made to the variable also change in the original.

Code: Select all


class TestClass(object):
    test_variable = 'this is a test variable'
    
eg.globals.test_class = TestClass
print 'original:', TestClass.test_variable
print 'variable:', eg.globals.test_class.test_variable

eg.globals.test_class.test_variable = 'it is a mutable object'
print 'variable:',eg.globals.test_class.test_variable
print 'original:', TestClass.test_variable

Now this is a really goofy thing when dealing with python scripts. add the code below to a python script

Code: Select all


try:
    print some_text
except NameError:
    some_text= 'this is some text'
now run the script.....nothing happens.
now run it again..
If you like the work I have been doing then feel free to Image

dan Edens
Posts: 16
Joined: Mon Sep 24, 2018 7:57 pm

Re: Chain mouse click macros

Post by dan Edens » Mon Apr 08, 2019 6:32 pm

I know about the globals, while i do need to change it because some of them are unnecessary, there are 3 other parts to the puzzle that use those variables. It's like 20-30 macro's in total, Have this whole dynamic click location setup where I can long press to set a hotkey than fire a click at a certain coordinate. Handles things like 30 hour long safety courses or pause/play for webbased radio.

I'm starting to get a feel for the "." system and I'll start doing that in the future.
I rarely type it out tho It's pasta haha. While I'm still figuring out the language i tend to paste and edit.

Really appreciate the comments, I knew it was disgusting but now I won't be doing a bunch of fixes I can do it at once.
Thanks again dude. I'ma have to donate soon or something for sure.
I'll clean it up and repost it.

User avatar
kgschlosser
Site Admin
Posts: 4620
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Chain mouse click macros

Post by kgschlosser » Mon Apr 08, 2019 8:55 pm

it's not disgusting if A it works. and B if you know what is going on with it.


The big trick to getting a style for yourself is being able to look at the code 6 months or a year from now. and being able to understand what is going on.
If you like the work I have been doing then feel free to Image

Post Reply