Exemplo n.º 1
0
def lockMouse():
    oldX, oldY = win32api.GetCursorPos()
    t_end = time.time() + 5
    while time.time() < t_end:
        win32api.SetCursorPos((oldX, oldY))
Exemplo n.º 2
0
def xy():
    x, y = win32api.GetCursorPos()
    return [x, y]
Exemplo n.º 3
0
    def _perform_click_input(
        button="left",
        coords=(None, None),
        double=False,
        button_down=True,
        button_up=True,
        wheel_dist=0,
        pressed="",
        key_down=True,
        key_up=True,
    ):
        """Perform a click action using SendInput

        All the *click_input() and *mouse_input() methods use this function.

        Thanks to a bug report from Tomas Walch (twalch) on sourceforge and code
        seen at http://msdn.microsoft.com/en-us/magazine/cc164126.aspx this
        function now always works the same way whether the mouse buttons are
        swapped or not.

        For example if you send a right click to Notepad.Edit - it will always
        bring up a popup menu rather than 'clicking' it.
        """

        # Handle if the mouse buttons are swapped
        if win32functions.GetSystemMetrics(win32defines.SM_SWAPBUTTON):
            if button.lower() == 'left':
                button = 'right'
            elif button.lower() == 'right':
                button = 'left'

        events = []
        if button.lower() == 'left':
            events.append(win32defines.MOUSEEVENTF_MOVE)
            if button_down:
                events.append(win32defines.MOUSEEVENTF_LEFTDOWN)
            if button_up:
                events.append(win32defines.MOUSEEVENTF_LEFTUP)
        elif button.lower() == 'right':
            if button_down:
                events.append(win32defines.MOUSEEVENTF_RIGHTDOWN)
            if button_up:
                events.append(win32defines.MOUSEEVENTF_RIGHTUP)
        elif button.lower() == 'middle':
            if button_down:
                events.append(win32defines.MOUSEEVENTF_MIDDLEDOWN)
            if button_up:
                events.append(win32defines.MOUSEEVENTF_MIDDLEUP)
        elif button.lower() == 'move':
            events.append(win32defines.MOUSEEVENTF_MOVE)
            events.append(win32defines.MOUSEEVENTF_ABSOLUTE)
        elif button.lower() == 'x':
            if button_down:
                events.append(win32defines.MOUSEEVENTF_XDOWN)
            if button_up:
                events.append(win32defines.MOUSEEVENTF_XUP)

        if button.lower() == 'wheel':
            events.append(win32defines.MOUSEEVENTF_WHEEL)

        # if we were asked to double click (and we are doing a full click
        # not just up or down.
        if double and button_down and button_up:
            events *= 2

        if button_down and (button.lower() not in ['move', 'wheel']):
            # wait while previous click is not affecting our current click
            while 0 < win32api.GetTickCount() - win32api.GetLastInputInfo(
            ) < win32gui.GetDoubleClickTime():
                time.sleep(Timings.after_clickinput_wait)

        # set the cursor position
        _set_cursor_pos((coords[0], coords[1]))
        time.sleep(Timings.after_setcursorpos_wait)
        if win32api.GetCursorPos() != (coords[0], coords[1]):
            _set_cursor_pos((coords[0], coords[1]))
            time.sleep(Timings.after_setcursorpos_wait)

        keyboard_keys = pressed.lower().split()
        if ('control' in keyboard_keys) and key_down:
            keyboard.VirtualKeyAction(keyboard.VK_CONTROL, up=False).run()
        if ('shift' in keyboard_keys) and key_down:
            keyboard.VirtualKeyAction(keyboard.VK_SHIFT, up=False).run()
        if ('alt' in keyboard_keys) and key_down:
            keyboard.VirtualKeyAction(keyboard.VK_MENU, up=False).run()

        dw_flags = 0
        for event in events:
            dw_flags |= event

        dw_data = 0
        if button.lower() == 'wheel':
            wheel_dist = wheel_dist * 120
            dw_data = wheel_dist

        if button.lower() == 'move':
            x_res = win32functions.GetSystemMetrics(win32defines.SM_CXSCREEN)
            y_res = win32functions.GetSystemMetrics(win32defines.SM_CYSCREEN)
            x_coord = int(float(coords[0]) * (65535. / float(x_res - 1)))
            y_coord = int(float(coords[1]) * (65535. / float(y_res - 1)))
            win32api.mouse_event(dw_flags, x_coord, y_coord, dw_data)
        else:
            for event in events:
                if event == win32defines.MOUSEEVENTF_MOVE:
                    x_res = win32functions.GetSystemMetrics(
                        win32defines.SM_CXSCREEN)
                    y_res = win32functions.GetSystemMetrics(
                        win32defines.SM_CYSCREEN)
                    x_coord = int(
                        float(coords[0]) * (65535. / float(x_res - 1)))
                    y_coord = int(
                        float(coords[1]) * (65535. / float(y_res - 1)))
                    win32api.mouse_event(
                        win32defines.MOUSEEVENTF_MOVE
                        | win32defines.MOUSEEVENTF_ABSOLUTE, x_coord, y_coord,
                        dw_data)
                else:
                    win32api.mouse_event(
                        event | win32defines.MOUSEEVENTF_ABSOLUTE, coords[0],
                        coords[1], dw_data)

        time.sleep(Timings.after_clickinput_wait)

        if ('control' in keyboard_keys) and key_up:
            keyboard.VirtualKeyAction(keyboard.VK_CONTROL, down=False).run()
        if ('shift' in keyboard_keys) and key_up:
            keyboard.VirtualKeyAction(keyboard.VK_SHIFT, down=False).run()
        if ('alt' in keyboard_keys) and key_up:
            keyboard.VirtualKeyAction(keyboard.VK_MENU, down=False).run()
Exemplo n.º 4
0
def get_cords():
    x, y = win32api.GetCursorPos()
    x = x - x_pad
    y = y - y_pad
    print(x, y)
Exemplo n.º 5
0
import win32api
import ctypes
import time
from time import sleep

## Instalar a parada abaixo
##pip install pypiwin32

savedpos = win32api.GetCursorPos()
count = 0
while (True):

    curpos = win32api.GetCursorPos()
    if savedpos != curpos:
        count = count + 1
        savedpos = curpos
        print("Mouse Movement # ", count)
    sleep(0.05)

#ctypes.windll.user32.LockWorkStation()
Exemplo n.º 6
0
windll.user32.SetProcessDPIAware()
time.sleep(5)
last_time = time.time()

#first create trainning data folder, if trainning data folder already exists, skip
if os.path.exists("TrainningDataFolder"):
    print("Trainning data exists, skipping creation")
else:
    print("making new directory")
    os.mkdir("TrainningDataFolder")
counter = 3  # taking picture per 100 second

while (True):

    x, y = win32api.GetCursorPos()

    print(x, y)
    screengrab = ImageGrab.grab(bbox=(x - 250, y - 250, x + 250, y + 250))
    # printscreen_numpy= np.array(printscreen_pil.getdata(), dtype = 'uint8').reshape( (printscreen_pil.size[1],printscreen_pil.size[0],3))

    print("time update : {} seconds".format(time.time() - last_time))
    last_time = time.time()
    #cv2.imshow('screen capture',cv2.cvtColor( np.array(screengrab),cv2.COLOR_BGR2RGB))
    counter -= 1
    print("COUNTER :  " + str(counter))

    if counter < 0:
        cv2.imwrite("TrainningDataFolder/" + str(time.time()) + ".png",
                    cv2.cvtColor(np.array(screengrab), cv2.COLOR_BGR2RGB))
        counter = 3
Exemplo n.º 7
0
 def just_click():
     x, y = win32api.GetCursorPos()
     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
     time.sleep(random.uniform(1.0, 0.2))
     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Exemplo n.º 8
0
 def _get_mouse_pos(cls):
     """
     :return: :class:`tuple` of `(x, y)`
     """
     return win32api.GetCursorPos()
Exemplo n.º 9
0
def getCords():
    x, y = win32api.GetCursorPos()
    x = x - Coordinates.x_pad
    y = y - Coordinates.y_pad
    return (x, y)
Exemplo n.º 10
0
 def move(self, a, b):
     x = self.current[0] + a
     y = self.current[1] + b
     win32api.SetCursorPos((int(x), int(y)))
     self.current = win32api.GetCursorPos()
Exemplo n.º 11
0
 def __init__(self):
     self.current = win32api.GetCursorPos()
Exemplo n.º 12
0
def main():
    params = {
        'win_title': 'The Journal 8',
        'use_ahk': 1,
        'mode': 0,
        'wait_t': 10,
        'scp_dst': '',
        'key_root': '',
        'key_dir': '',
        'auth_root': '',
        'auth_dir': '',
        'auth_file': '',
        'auth_path': '',
        'dst_path': '.',
        'scp_path': '.',
        'scp_name': 'grs',
    }
    paramparse.process_dict(params)

    win_title = params['win_title']
    use_ahk = params['use_ahk']
    mode = params['mode']
    wait_t = params['wait_t']
    scp_dst = params['scp_dst']
    dst_path = params['dst_path']
    scp_path = params['scp_path']
    scp_name = params['scp_name']

    key_root = params['key_root']
    key_dir = params['key_dir']
    auth_root = params['auth_root']
    auth_dir = params['auth_dir']
    auth_file = params['auth_file']

    # Window.get_all_windows()

    if mode == -1 or mode == -2:
        pwd0 = auth_file
        port = None
    else:
        auth_path = linux_path(auth_root, auth_dir, auth_file)
        auth_data = open(auth_path, 'r').readlines()
        auth_data = [k.strip() for k in auth_data]

        dst_info = auth_data[0].split(' ')
        name00, name01, ecr0, key0 = dst_info[:4]

        if len(dst_info) > 4:
            port = dst_info[4]

        encryption_params = encryption.Params()
        encryption_params.mode = 1
        encryption_params.root_dir = key_root
        encryption_params.parent_dir = key_dir

        encryption_params.in_file = ecr0
        encryption_params.key_file = key0
        encryption_params.process()
        pwd0 = encryption.run(encryption_params)

    # Form1.SetFocus()
    default_fmy_key = '0'
    if mode == 0 or mode == -1:
        data_type = 'filename (from)'
        highlight_key = '2'
    elif mode == 1 or mode == -2:
        data_type = 'filename (to)'
        highlight_key = '3'
    elif mode == 2:
        data_type = 'log'
        highlight_key = '4'

    while True:
        k = input('\nEnter {}\n'.format(data_type))

        if not k:
            continue

        x, y = win32api.GetCursorPos()
        # EnumWindows(EnumWindowsProc(foreach_window), 0)
        if use_ahk:
            if mode == 0 or mode == -1:
                clip_txt = '{} from {}'.format(k, scp_name)
            elif mode == 1 or mode == -2:
                clip_txt = '{} to {}'.format(k, scp_name)

            try:
                import pyperclip

                pyperclip.copy(clip_txt)
                _ = pyperclip.paste()
            except BaseException as e:
                print('Copying to clipboard failed: {}'.format(e))

            os.system('paste_with_cat_1')
            run_scp(dst_path, pwd0, scp_dst, scp_path, k, mode, port)
            continue

        GetWindowText = ctypes.windll.user32.GetWindowTextW
        GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
        IsWindowVisible = ctypes.windll.user32.IsWindowVisible

        titles = []

        def foreach_window(hwnd, lParam):
            if IsWindowVisible(hwnd):
                length = GetWindowTextLength(hwnd)
                buff = ctypes.create_unicode_buffer(length + 1)
                GetWindowText(hwnd, buff, length + 1)
                titles.append((hwnd, buff.value))
            return True

        win32gui.EnumWindows(foreach_window, None)

        # for i in range(len(titles)):
        #     print(titles[i])

        target_title = [k[1] for k in titles if k[1].startswith(win_title)]
        # print('target_title: {}'.format(target_title))

        if not target_title:
            print('Window with win_title: {} not found'.format(win_title))
            run_scp(dst_path, pwd0, scp_dst, scp_path, k, mode, port)
            continue

        target_title = target_title[0]
        # print('target_title: {}'.format(target_title))

        try:
            app = application.Application().connect(title=target_title,
                                                    found_index=0)
        except BaseException as e:
            print('Failed to connect to app for window {}: {}'.format(
                target_title, e))
            run_scp(dst_path, pwd0, scp_dst, scp_path, k, mode, port)
            continue
        try:
            app_win = app.window(title=target_title)
        except BaseException as e:
            print('Failed to access app window for {}: {}'.format(
                target_title, e))
            run_scp(dst_path, pwd0, scp_dst, scp_path, k, mode, port)
            continue

        try:
            # if mode == 2:
            #     enable_highlight = k.strip()
            #     app_win.type_keys("^t~")
            #     app_win.type_keys("^v")
            #     app_win.type_keys("^+a")
            #     if enable_highlight:
            #         app_win.type_keys("^+%a")
            #         # time.sleep(1)
            #         app_win.type_keys("^+z")
            #         app_win.type_keys("{RIGHT}{VK_SPACE}~")
            #     else:
            #         app_win.type_keys("{VK_SPACE}~")
            #
            #     app_win.type_keys("^s")
            #     continue

            app_win.type_keys("^t{VK_SPACE}::{VK_SPACE}1")
            app_win.type_keys("^+a")
            app_win.type_keys("^2")
            # app_win.type_keys("^+1")
            app_win.type_keys("{RIGHT}{LEFT}~")
            app_win.type_keys("^v")
            if mode == 1:
                app_win.type_keys("{LEFT}{RIGHT}{VK_SPACE}to{VK_SPACE}%s" %
                                  scp_name)
            # app_win.type_keys("^+a")
            # app_win.type_keys("^{}".format(highlight_key))
            # app_win.type_keys("{LEFT}{RIGHT}~")
            # app_win.type_keys("^{}".format(default_fmy_key))
            app_win.type_keys("~")
            app_win.type_keys("^s")

            mouse.move(coords=(x, y))
        except BaseException as e:
            print('Failed to type entry in app : {}'.format(e))
            pass

        run_scp(dst_path, pwd0, scp_dst, scp_path, k, mode, port)
Exemplo n.º 13
0
 def __init__(self):
     self.key_list = list(range(ord('A'), ord('Z') + 1)) + \
                     [win32con.VK_SPACE, win32con.VK_UP, win32con.VK_DOWN, win32con.VK_LEFT,
                      win32con.VK_RIGHT]
     self.last_mouse_position = win32api.GetCursorPos()
     self.activity_count = 0
Exemplo n.º 14
0
def application():
	prev_pos=win32api.GetCursorPos()
	time.sleep(30)
	cur_pos =win32api.GetCursorPos()
	if(prev_pos==cur_pos ):
		movemouse()