1
# -*- coding: iso-8859-1 -*-
3
# Copyright 2010 Pepijn de Vos
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
# you may not use this file except in compliance with the License.
7
# You may obtain a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
17
clicks = [None, 2, 8, 32]
18
releases = [None, 4, 16, 64]
21
from win32api import GetSystemMetrics
22
from base import PyMouseMeta, PyMouseEventMeta
23
import pythoncom, pyHook
24
from time import sleep
26
PUL = POINTER(c_ulong)
27
class MouseInput(Structure):
28
_fields_ = [("dx", c_long),
30
("mouseData", c_ulong),
36
_fields_ = [("mi", MouseInput)]
38
class Input(Structure):
39
_fields_ = [("type", c_ulong), ("ii", Input_I)]
45
click.mi = MouseInput(0, 0, 0, 2, 0, pointer(extra))
47
release.mi = MouseInput(0, 0, 0, 4, 0, pointer(extra))
49
blob = FInputs( (0, click), (0, release) )
51
class POINT(Structure):
52
_fields_ = [("x", c_ulong),
55
class PyMouse(PyMouseMeta):
56
def press(self, x, y, button = 1):
58
blob[0].ii.mi.dwFlags = clicks[button]
59
windll.user32.SendInput(2,pointer(blob),sizeof(blob[0]))
61
def release(self, x, y, button = 1):
63
blob[1].ii.mi.dwFlags = releases[button]
64
windll.user32.SendInput(2,pointer(blob),sizeof(blob[0]))
67
windll.user32.SetCursorPos(x, y)
71
windll.user32.GetCursorPos(byref(pt))
74
def screen_size(self):
75
width = GetSystemMetrics(0)
76
height = GetSystemMetrics(1)
79
class PyMouseEvent(PyMouseEventMeta):
81
hm = pyHook.HookManager()
82
hm.MouseAllButtons = self._click
83
hm.MouseMove = self._move
88
pythoncom.PumpWaitingMessages()
90
def _click(self, event):
93
if event.Message == pyHook.HookConstants.WM_LBUTTONDOWN:
94
self.click(x, y, 1, True)
95
elif event.Message == pyHook.HookConstants.WM_LBUTTONUP:
96
self.click(x, y, 1, False)
97
elif event.Message == pyHook.HookConstants.WM_RBUTTONDOWN:
98
self.click(x, y, 2, True)
99
elif event.Message == pyHook.HookConstants.WM_RBUTTONUP:
100
self.click(x, y, 2, False)
101
elif event.Message == pyHook.HookConstants.WM_MBUTTONDOWN:
102
self.click(x, y, 3, True)
103
elif event.Message == pyHook.HookConstants.WM_MBUTTONUP:
104
self.click(x, y, 3, False)
105
return not self.capture
107
def _move(self, event):
110
return not self.capture