Python Quartz.CGEventPost() Examples

The following are 30 code examples of Quartz.CGEventPost(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Quartz , or try the search function .
Example #1
Source File: _pyautogui_osx.py    From xbmc with GNU General Public License v3.0 6 votes vote down vote up
def _specialKeyEvent(key, upDown):
    """ Helper method for special keys.

    Source: http://stackoverflow.com/questions/11045814/emulate-media-key-press-on-mac
    """
    assert upDown in ('up', 'down'), "upDown argument must be 'up' or 'down'"

    key_code = special_key_translate_table[key]

    ev = AppKit.NSEvent.otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(
            Quartz.NSSystemDefined, # type
            (0,0), # location
            0xa00 if upDown == 'down' else 0xb00, # flags
            0, # timestamp
            0, # window
            0, # ctx
            8, # subtype
            (key_code << 16) | ((0xa if upDown == 'down' else 0xb) << 8), # data1
            -1 # data2
        )

    Quartz.CGEventPost(0, ev.CGEvent()) 
Example #2
Source File: _pyautogui_osx.py    From Dindo-Bot with MIT License 6 votes vote down vote up
def _hscroll(clicks, x=None, y=None):
    _moveTo(x, y)
    clicks = int(clicks)
    for _ in range(abs(clicks) // 10):
        scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
            None, # no source
            Quartz.kCGScrollEventUnitLine, # units
            2, # wheelCount (number of dimensions)
            0, # vertical movement
            10 if clicks >= 0 else -10) # horizontal movement
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent)

    scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
        None, # no source
        Quartz.kCGScrollEventUnitLine, # units
        2, # wheelCount (number of dimensions)
        0, # vertical movement
        (clicks % 10) if clicks >= 0 else (-1 * clicks % 10)) # horizontal movement
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent) 
Example #3
Source File: _pyautogui_osx.py    From Dindo-Bot with MIT License 6 votes vote down vote up
def _vscroll(clicks, x=None, y=None):
    _moveTo(x, y)
    clicks = int(clicks)
    for _ in range(abs(clicks) // 10):
        scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
            None, # no source
            Quartz.kCGScrollEventUnitLine, # units
            1, # wheelCount (number of dimensions)
            10 if clicks >= 0 else -10) # vertical movement
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent)

    scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
        None, # no source
        Quartz.kCGScrollEventUnitLine, # units
        1, # wheelCount (number of dimensions)
        clicks % 10 if clicks >= 0 else -1 * (-clicks % 10)) # vertical movement
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent) 
Example #4
Source File: _pyautogui_osx.py    From Dindo-Bot with MIT License 6 votes vote down vote up
def _specialKeyEvent(key, upDown):
    """ Helper method for special keys.

    Source: http://stackoverflow.com/questions/11045814/emulate-media-key-press-on-mac
    """
    assert upDown in ('up', 'down'), "upDown argument must be 'up' or 'down'"

    key_code = special_key_translate_table[key]

    ev = AppKit.NSEvent.otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(
            Quartz.NSSystemDefined, # type
            (0,0), # location
            0xa00 if upDown == 'down' else 0xb00, # flags
            0, # timestamp
            0, # window
            0, # ctx
            8, # subtype
            (key_code << 16) | ((0xa if upDown == 'down' else 0xb) << 8), # data1
            -1 # data2
        )

    Quartz.CGEventPost(0, ev.CGEvent()) 
Example #5
Source File: _pyautogui_osx.py    From Dindo-Bot with MIT License 6 votes vote down vote up
def _normalKeyEvent(key, upDown):
    assert upDown in ('up', 'down'), "upDown argument must be 'up' or 'down'"

    try:
        if pyautogui.isShiftCharacter(key):
            key_code = keyboardMapping[key.lower()]

            event = Quartz.CGEventCreateKeyboardEvent(None,
                        keyboardMapping['shift'], upDown == 'down')
            Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)
            # Tiny sleep to let OS X catch up on us pressing shift
            time.sleep(0.01)

        else:
            key_code = keyboardMapping[key]

        event = Quartz.CGEventCreateKeyboardEvent(None, key_code, upDown == 'down')
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)
        time.sleep(0.01)

    # TODO - wait, is the shift key's keyup not done?
    # TODO - get rid of this try-except.

    except KeyError:
        raise RuntimeError("Key %s not implemented." % (key)) 
Example #6
Source File: _pyautogui_osx.py    From xbmc with GNU General Public License v3.0 6 votes vote down vote up
def _normalKeyEvent(key, upDown):
    assert upDown in ('up', 'down'), "upDown argument must be 'up' or 'down'"

    try:
        if pyautogui.isShiftCharacter(key):
            key_code = keyboardMapping[key.lower()]

            event = Quartz.CGEventCreateKeyboardEvent(None,
                        keyboardMapping['shift'], upDown == 'down')
            Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)
            # Tiny sleep to let OS X catch up on us pressing shift
            time.sleep(0.01)

        else:
            key_code = keyboardMapping[key]

        event = Quartz.CGEventCreateKeyboardEvent(None, key_code, upDown == 'down')
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)
        time.sleep(0.01)

    # TODO - wait, is the shift key's keyup not done?
    # TODO - get rid of this try-except.

    except KeyError:
        raise RuntimeError("Key %s not implemented." % (key)) 
Example #7
Source File: _pyautogui_osx.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _hscroll(clicks, x=None, y=None):
    _moveTo(x, y)
    clicks = int(clicks)
    for _ in range(abs(clicks) // 10):
        scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
            None, # no source
            Quartz.kCGScrollEventUnitLine, # units
            2, # wheelCount (number of dimensions)
            0, # vertical movement
            10 if clicks >= 0 else -10) # horizontal movement
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent)

    scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
        None, # no source
        Quartz.kCGScrollEventUnitLine, # units
        2, # wheelCount (number of dimensions)
        0, # vertical movement
        (clicks % 10) if clicks >= 0 else (-1 * clicks % 10)) # horizontal movement
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent) 
Example #8
Source File: _pyautogui_osx.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _vscroll(clicks, x=None, y=None):
    _moveTo(x, y)
    clicks = int(clicks)
    for _ in range(abs(clicks) // 10):
        scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
            None, # no source
            Quartz.kCGScrollEventUnitLine, # units
            1, # wheelCount (number of dimensions)
            10 if clicks >= 0 else -10) # vertical movement
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent)

    scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
        None, # no source
        Quartz.kCGScrollEventUnitLine, # units
        1, # wheelCount (number of dimensions)
        clicks % 10 if clicks >= 0 else -1 * (-clicks % 10)) # vertical movement
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent) 
Example #9
Source File: _pyautogui_osx.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _specialKeyEvent(key, upDown):
    """ Helper method for special keys.

    Source: http://stackoverflow.com/questions/11045814/emulate-media-key-press-on-mac
    """
    assert upDown in ('up', 'down'), "upDown argument must be 'up' or 'down'"

    key_code = special_key_translate_table[key]

    ev = AppKit.NSEvent.otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(
            Quartz.NSSystemDefined, # type
            (0,0), # location
            0xa00 if upDown == 'down' else 0xb00, # flags
            0, # timestamp
            0, # window
            0, # ctx
            8, # subtype
            (key_code << 16) | ((0xa if upDown == 'down' else 0xb) << 8), # data1
            -1 # data2
        )

    Quartz.CGEventPost(0, ev.CGEvent()) 
Example #10
Source File: _pyautogui_osx.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _normalKeyEvent(key, upDown):
    assert upDown in ('up', 'down'), "upDown argument must be 'up' or 'down'"

    try:
        if pyautogui.isShiftCharacter(key):
            key_code = keyboardMapping[key.lower()]

            event = Quartz.CGEventCreateKeyboardEvent(None,
                        keyboardMapping['shift'], upDown == 'down')
            Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)
            # Tiny sleep to let OS X catch up on us pressing shift
            time.sleep(0.01)

        else:
            key_code = keyboardMapping[key]

        event = Quartz.CGEventCreateKeyboardEvent(None, key_code, upDown == 'down')
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)
        time.sleep(0.01)

    # TODO - wait, is the shift key's keyup not done?
    # TODO - get rid of this try-except.

    except KeyError:
        raise RuntimeError("Key %s not implemented." % (key)) 
Example #11
Source File: _pyautogui_osx.py    From xbmc with GNU General Public License v3.0 6 votes vote down vote up
def _vscroll(clicks, x=None, y=None):
    _moveTo(x, y)
    clicks = int(clicks)
    for _ in range(abs(clicks) // 10):
        scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
            None, # no source
            Quartz.kCGScrollEventUnitLine, # units
            1, # wheelCount (number of dimensions)
            10 if clicks >= 0 else -10) # vertical movement
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent)

    scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
        None, # no source
        Quartz.kCGScrollEventUnitLine, # units
        1, # wheelCount (number of dimensions)
        clicks % 10 if clicks >= 0 else -1 * (-clicks % 10)) # vertical movement
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent) 
Example #12
Source File: _pyautogui_osx.py    From xbmc with GNU General Public License v3.0 6 votes vote down vote up
def _hscroll(clicks, x=None, y=None):
    _moveTo(x, y)
    clicks = int(clicks)
    for _ in range(abs(clicks) // 10):
        scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
            None, # no source
            Quartz.kCGScrollEventUnitLine, # units
            2, # wheelCount (number of dimensions)
            0, # vertical movement
            10 if clicks >= 0 else -10) # horizontal movement
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent)

    scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
        None, # no source
        Quartz.kCGScrollEventUnitLine, # units
        2, # wheelCount (number of dimensions)
        0, # vertical movement
        (clicks % 10) if clicks >= 0 else (-1 * clicks % 10)) # horizontal movement
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent) 
Example #13
Source File: _darwin.py    From MIA-Dictionary-Addon with GNU General Public License v3.0 6 votes vote down vote up
def _scroll(self, dx, dy):
        while dx != 0 or dy != 0:
            xval = 1 if dx > 0 else -1 if dx < 0 else 0
            dx -= xval
            yval = 1 if dy > 0 else -1 if dy < 0 else 0
            dy -= yval

            Quartz.CGEventPost(
                Quartz.kCGHIDEventTap,
                Quartz.CGEventCreateScrollWheelEvent(
                    None,
                    Quartz.kCGScrollEventUnitPixel,
                    2,
                    yval * self._SCROLL_SPEED,
                    xval * self._SCROLL_SPEED)) 
Example #14
Source File: _darwin.py    From MIA-Dictionary-Addon with GNU General Public License v3.0 6 votes vote down vote up
def _press(self, button):
        (press, _, _), mouse_button = button.value
        event = Quartz.CGEventCreateMouseEvent(
            None,
            press,
            self.position,
            mouse_button)

        # If we are performing a click, we need to set this state flag
        if self._click is not None:
            self._click += 1
            Quartz.CGEventSetIntegerValueField(
                event,
                Quartz.kCGMouseEventClickState,
                self._click)

        Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)

        # Store the button to enable dragging
        self._drag_button = button 
Example #15
Source File: _darwin.py    From MIA-Dictionary-Addon with GNU General Public License v3.0 6 votes vote down vote up
def _release(self, button):
        (_, release, _), mouse_button = button.value
        event = Quartz.CGEventCreateMouseEvent(
            None,
            release,
            self.position,
            mouse_button)

        # If we are performing a click, we need to set this state flag
        if self._click is not None:
            Quartz.CGEventSetIntegerValueField(
                event,
                Quartz.kCGMouseEventClickState,
                self._click)

        Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)

        if button == self._drag_button:
            self._drag_button = None 
Example #16
Source File: OSXUIFunc.py    From Poco with Apache License 2.0 5 votes vote down vote up
def rclick(x, y, button=2):
        theEvent = Quartz.CGEventCreateMouseEvent(None, pressID[button], (x, y), button - 1)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent)  
        Quartz.CGEventSetType(theEvent, releaseID[button])  
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent) 
Example #17
Source File: OSXUIFunc.py    From Poco with Apache License 2.0 5 votes vote down vote up
def drag(x, y):
        drag = Quartz.CGEventCreateMouseEvent(None, Quartz.kCGEventLeftMouseDragged, (x, y), 0)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, drag) 
Example #18
Source File: OSXUIFunc.py    From Poco with Apache License 2.0 5 votes vote down vote up
def doubleclick(x, y, button=1):
        theEvent = Quartz.CGEventCreateMouseEvent(None, pressID[button], (x, y), button - 1)
        Quartz.CGEventSetIntegerValueField(theEvent, Quartz.kCGMouseEventClickState, 2)  
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent)  
        Quartz.CGEventSetType(theEvent, Quartz.kCGEventLeftMouseUp)  
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent)  
        Quartz.CGEventSetType(theEvent, Quartz.kCGEventLeftMouseDown) 
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent)
        Quartz.CGEventSetType(theEvent, Quartz.kCGEventLeftMouseUp)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent) 
Example #19
Source File: _darwin.py    From MIA-Dictionary-Addon with GNU General Public License v3.0 5 votes vote down vote up
def _handle(self, key, is_press):
        with self.modifiers as modifiers:
            Quartz.CGEventPost(
                Quartz.kCGHIDEventTap,
                (key if key not in Key else key.value)._event(
                    modifiers, self._mapping, is_press)) 
Example #20
Source File: OSXUIFunc.py    From Poco with Apache License 2.0 5 votes vote down vote up
def scroll(vertical=None, horizontal=None, depth=None):
        # Local submethod for generating Mac scroll events in one axis at a time
        def scroll_event(y_move=0, x_move=0, z_move=0, n=1):
            for _ in range(abs(n)):
                scrollWheelEvent = Quartz.CGEventCreateScrollWheelEvent(
                    None,  # No source
                    Quartz.kCGScrollEventUnitLine,  # Unit of measurement is lines
                    3,  # Number of wheels(dimensions)
                    y_move,
                    x_move,
                    z_move)
                Quartz.CGEventPost(Quartz.kCGHIDEventTap, scrollWheelEvent)

        # Execute vertical then horizontal then depth scrolling events
        if vertical is not None:
            vertical = int(vertical)
            if vertical == 0:   # Do nothing with 0 distance
                pass
            elif vertical > 0:  # Scroll up if positive
                scroll_event(y_move=1, n=vertical)
            else:  # Scroll down if negative
                scroll_event(y_move=-1, n=abs(vertical))
        if horizontal is not None:
            horizontal = int(horizontal)
            if horizontal == 0:  # Do nothing with 0 distance
                pass
            elif horizontal > 0:  # Scroll right if positive
                scroll_event(x_move=1, n=horizontal)
            else:  # Scroll left if negative
                scroll_event(x_move=-1, n=abs(horizontal))
        if depth is not None:
            depth = int(depth)
            if depth == 0:  # Do nothing with 0 distance
                pass
            elif vertical > 0:  # Scroll "out" if positive
                scroll_event(z_move=1, n=depth)
            else:  # Scroll "in" if negative
                scroll_event(z_move=-1, n=abs(depth)) 
Example #21
Source File: _pyautogui_osx.py    From xbmc with GNU General Public License v3.0 5 votes vote down vote up
def _multiClick(x, y, button, num):
    btn    = None
    down   = None
    up     = None

    if button == LEFT:
        btn  = Quartz.kCGMouseButtonLeft
        down = Quartz.kCGEventLeftMouseDown
        up   = Quartz.kCGEventLeftMouseUp
    elif button == MIDDLE:
        btn  = Quartz.kCGMouseButtonCenter
        down = Quartz.kCGEventOtherMouseDown
        up   = Quartz.kCGEventOtherMouseUp
    elif button == RIGHT:
        btn  = Quartz.kCGMouseButtonRight
        down = Quartz.kCGEventRightMouseDown
        up   = Quartz.kCGEventRightMouseUp
    else:
        assert False, "button argument not in ('left', 'middle', 'right')"
        return

    mouseEvent = Quartz.CGEventCreateMouseEvent(None, down, (x, y), btn)
    Quartz.CGEventSetIntegerValueField(mouseEvent, Quartz.kCGMouseEventClickState, num)
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent)
    Quartz.CGEventSetType(mouseEvent, up)
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent)
    for i in range(0, num-1):
        Quartz.CGEventSetType(mouseEvent, down)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent)
        Quartz.CGEventSetType(mouseEvent, up)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent) 
Example #22
Source File: _darwin.py    From MIA-Dictionary-Addon with GNU General Public License v3.0 5 votes vote down vote up
def _position_set(self, pos):
        try:
            (_, _, mouse_type), mouse_button = self._drag_button.value
        except AttributeError:
            mouse_type = Quartz.kCGEventMouseMoved
            mouse_button = 0

        Quartz.CGEventPost(
            Quartz.kCGHIDEventTap,
            Quartz.CGEventCreateMouseEvent(
                None,
                mouse_type,
                pos,
                mouse_button)) 
Example #23
Source File: eye_detection.py    From Mousely with MIT License 5 votes vote down vote up
def __mouse_event(self, type, x, y):
        mouse_event = Quartz.CGEventCreateMouseEvent(None, type, (x, y), Quartz.kCGMouseButtonLeft)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouse_event) 
Example #24
Source File: OSXUIFunc.py    From Poco with Apache License 2.0 5 votes vote down vote up
def click(x, y, button=1):
        theEvent = Quartz.CGEventCreateMouseEvent(None, pressID[button], (x, y), button - 1)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent)  
        Quartz.CGEventSetType(theEvent, Quartz.kCGEventLeftMouseUp)  
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent) 
Example #25
Source File: OSXUIFunc.py    From Poco with Apache License 2.0 5 votes vote down vote up
def release(x, y, button=1):
        event = Quartz.CGEventCreateMouseEvent(None, releaseID[button], (x, y), button - 1)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, event) 
Example #26
Source File: OSXUIFunc.py    From Poco with Apache License 2.0 5 votes vote down vote up
def press(x, y, button=1):
        event = Quartz.CGEventCreateMouseEvent(None, pressID[button], (x, y), button - 1)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, event) 
Example #27
Source File: _pyautogui_osx.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def _multiClick(x, y, button, num):
    btn    = None
    down   = None
    up     = None

    if button == LEFT:
        btn  = Quartz.kCGMouseButtonLeft
        down = Quartz.kCGEventLeftMouseDown
        up   = Quartz.kCGEventLeftMouseUp
    elif button == MIDDLE:
        btn  = Quartz.kCGMouseButtonCenter
        down = Quartz.kCGEventOtherMouseDown
        up   = Quartz.kCGEventOtherMouseUp
    elif button == RIGHT:
        btn  = Quartz.kCGMouseButtonRight
        down = Quartz.kCGEventRightMouseDown
        up   = Quartz.kCGEventRightMouseUp
    else:
        assert False, "button argument not in ('left', 'middle', 'right')"
        return

    mouseEvent = Quartz.CGEventCreateMouseEvent(None, down, (x, y), btn)
    Quartz.CGEventSetIntegerValueField(mouseEvent, Quartz.kCGMouseEventClickState, num)
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent)
    Quartz.CGEventSetType(mouseEvent, up)
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent)
    for i in range(0, num-1):
        Quartz.CGEventSetType(mouseEvent, down)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent)
        Quartz.CGEventSetType(mouseEvent, up)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent) 
Example #28
Source File: _pyautogui_osx.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _multiClick(x, y, button, num):
    btn    = None
    down   = None
    up     = None

    if button == LEFT:
        btn  = Quartz.kCGMouseButtonLeft
        down = Quartz.kCGEventLeftMouseDown
        up   = Quartz.kCGEventLeftMouseUp
    elif button == MIDDLE:
        btn  = Quartz.kCGMouseButtonCenter
        down = Quartz.kCGEventOtherMouseDown
        up   = Quartz.kCGEventOtherMouseUp
    elif button == RIGHT:
        btn  = Quartz.kCGMouseButtonRight
        down = Quartz.kCGEventRightMouseDown
        up   = Quartz.kCGEventRightMouseUp
    else:
        assert False, "button argument not in ('left', 'middle', 'right')"
        return

    mouseEvent = Quartz.CGEventCreateMouseEvent(None, down, (x, y), btn)
    Quartz.CGEventSetIntegerValueField(mouseEvent, Quartz.kCGMouseEventClickState, num)
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent)
    Quartz.CGEventSetType(mouseEvent, up)
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent)
    for i in range(0, num-1):
        Quartz.CGEventSetType(mouseEvent, down)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent)
        Quartz.CGEventSetType(mouseEvent, up)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouseEvent) 
Example #29
Source File: mouse.py    From Mousely with MIT License 5 votes vote down vote up
def move_rel(self, x, y):
        [x, y] = self.torelative(x, y)
        moveEvent = Quartz.CGEventCreateMouseEvent(None, Quartz.kCGEventMouseMoved, Quartz.CGPointMake(x, y), 0)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, moveEvent) 
Example #30
Source File: mouse.py    From Mousely with MIT License 5 votes vote down vote up
def doubleClick(self, x, y, clickCount, button=0):
        print("Double click event")
        theEvent = Quartz.CGEventCreateMouseEvent(None, Mouse.down[button], (x, y), button)
        Quartz.CGEventSetIntegerValueField(theEvent, Quartz.kCGMouseEventClickState, clickCount)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent)
        Quartz.CGEventSetType(theEvent, Quartz.kCGEventLeftMouseUp)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent)
        Quartz.CGEventSetType(theEvent, Quartz.kCGEventLeftMouseDown)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent)
        Quartz.CGEventSetType(theEvent, Quartz.kCGEventLeftMouseUp)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, theEvent)
        print("Double click event ended")