Create a macro. add the Python Script action to the macro. copy and paste the code below into that script.
Click on apply and then click on OK.
drag and drop one of the udp.(x, y) events into the macro.
double click on the event in the macro
Change it to read
udp.*
Code: Select all
# make sure you read the comments to know what is going on
from eg.WinApi.Utils import GetMonitorDimensions
import wx
# udp.(154, 142)
try:
coords = eval(eg.event.string.split('.')[-1])
except:
eg.Exit()
if not isinstance(coords, tuple):
eg.Exit()
x, y = coords
DEMOPAD_WIDTH = 500
DEMOPAD_HEIGHT = 300
# I do not know if you have multiple monitors or not.
# if you do do it is possible to end up with negative
# x and y start positions. So we need to account for that
# properly. we also need to get the total width and total
# height of all of the monitors. GetMonitorDimensions
# does some magic for us. It returns the monitors that
# are attached to the system and tells us where the 0, 0
# position of that monitor actually is. and also the width
# and height of the monitor.
rect = wx.Rect()
for monitor in GetMonitorDimensions():
# because of some back end magic we are able to "join" the
# monitors to get a single monitor. This is only for the
# purposes of math and it does nothing to your actual display.
rect.Union(monitor)
# now that we have a single "monitor" that represents all of the
# displays that are attached. we are able to get the starting point
# and also the ending point of the combined displays.
SCREEN_START_X = rect.GetX()
SCREEN_START_Y = rect.GetY()
# in order to know where the end point is we add the start point to the width/height
SCREEN_END_X = SCREEN_START_X + rect.GetWidth()
SCREEN_END_Y = SCREEN_START_Y + rect.GetHeight()
# this function takes a value that is within a given range and "re maps"
# it to a new range of numbers.
# this is how we turn the x, y for a screen size of 500, 300 into
# the x, y of your combined displays
def remap(value, old_min, old_max, new_min, new_max):
old_range = old_max - old_min
new_range = new_max - new_min
return (((value - old_min) * new_range) / old_range) + new_min
# the conversion.
x = remap(x, 0, DEMOPAD_WIDTH, SCREEN_START_X, SCREEN_END_X)
y = remap(y, 0, DEMOPAD_HEIGHT, SCREEN_START_Y, SCREEN_END_Y)
# we need to use a wx.Point object to pass to a monitor to see
# if the x, y is within that monitor
point = wx.Point(x, y)
for monitor_num, monitor in enumerate(GetMonitorDimensions()):
# checking to see if the remapped x, y are in a given monitor.
if monitor.Contains(point):
# now this is the tricky part. the Mouse action does not deal
# in the x, y of a combined display. each display always starts at
# 0, 0 and ends at width, height. So now we need to convert the x, y
# into the x, y needed for this display.
x_min = monitor.GetX()
x_max = x_min + monitor.GetWidth()
y_min = monitor.GetY()
y_max = y_min + monitor.GetHeight()
# here is the conversion. so the old min and max are the "real" start and end positions
# for the display. the new range is 0 to the width/heigh. This is going to give us the x, y
# that the mouse action needs.
x = remap(x, x_min, x_max, 0, monitor.GetWidth())
y = remap(y, y_min, y_max, 0, monitor.GetHeight())
# and here we call the action and move the mouse.
eg.plugins.Mouse.MoveAbsolute(x, y, monitor_num, False, False)
# if we found the monitor there is no point in checking any other ones.
# so we break out of checking the rest of them
break
else:
# This code gets run if no monitor is found. This would be a catastrophic
# failure of the above code. and tells us that something is horrifically wrong.
# If you ever see this printed in your log you have to let me know and I will
# have to locate the error.
print 'No monitor found'
Here is another way to move the mouse. This uses direction and speed instead of x, y. This is going to function like a laptop trackpad does.
You will need to make some adjustments to dial it in. there are 2 varis that you will need to tinker with to dial it in right.
Code: Select all
# duration until reset occurs in milliseconds. 1000 = 1 second.
RESET_DURATION = 1000
# adjust this humber down to dial in the speed of the mouse movement
# you may want to adjust it in 10000 increments at fi and then 1000
and so on and so forth
SPEED = 65535
DEMOPAD_WIDTH = 500
DEMOPAD_HEIGHT = 300
import time
end_time = time.time()
try:
duration = (end_time - start_time) * 1000
last_x, last_y = eg.globals.last_mouse_coords
except:
duration = RESET_DURATION
last_x = 0
last_y = 0
import ctypes
import threading
from ctypes.wintypes import DWORD
if ctypes.sizeof(ctypes.c_void_p) == 8:
ULONG_PTR = ctypes.c_ulonglong
else:
ULONG_PTR = ctypes.c_ulong
user32 = ctypes.windll.User32
# void mouse_event(
# DWORD dwFlags,
# DWORD dx,
# DWORD dy,
# DWORD dwData,
# ULONG_PTR dwExtraInfo
# );
mouse_event = user32.mouse_event
mouse_event.restype = None
MOUSEEVENTF_MOVE = 0x0001
coords = eg.event.string.split('.')[-1]
try:
coords = eval(coords)
except:
eg.Exit()
if not isinstance(coords, tuple):
eg.Exit()
x, y = coords
def remap(value, old_min, old_max, new_min, new_max):
old_range = old_max - old_min
new_range = new_max - new_min
return (((value - old_min) * new_range) / old_range) + new_min
x = remap(x, 0, DEMOPAD_WIDTH, 0, SPEED)
y = remap(y, 0, DEMOPAD_HEIGHT, 0, SPEED)
eg.globals.last_mouse_coords = (x, y)
if duration >= RESET_DURATION:
last_x = x
last_y = y
x -= last_x
y -= last_y
print x, y
dwFlags = DWORD(MOUSEEVENTF_MOVE)
dx = DWORD(x)
dy = DWORD(y)
dwData =DWORD(0)
dwExtraInfo = ULONG_PTR()
mouse_event(dwFlags, dx, dy, dwData, dwExtraInfo)
start_time = time.time()