當前位置: 首頁>>代碼示例>>Python>>正文


Python Quartz.CGEventPost方法代碼示例

本文整理匯總了Python中Quartz.CGEventPost方法的典型用法代碼示例。如果您正苦於以下問題:Python Quartz.CGEventPost方法的具體用法?Python Quartz.CGEventPost怎麽用?Python Quartz.CGEventPost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Quartz的用法示例。


在下文中一共展示了Quartz.CGEventPost方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _normalKeyEvent

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
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)) 
開發者ID:asweigart,項目名稱:pyautogui,代碼行數:27,代碼來源:_pyautogui_osx.py

示例2: _specialKeyEvent

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
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()) 
開發者ID:asweigart,項目名稱:pyautogui,代碼行數:24,代碼來源:_pyautogui_osx.py

示例3: _vscroll

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
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) 
開發者ID:asweigart,項目名稱:pyautogui,代碼行數:19,代碼來源:_pyautogui_osx.py

示例4: _hscroll

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
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) 
開發者ID:asweigart,項目名稱:pyautogui,代碼行數:21,代碼來源:_pyautogui_osx.py

示例5: _press

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
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 
開發者ID:mass-immersion-approach,項目名稱:MIA-Dictionary-Addon,代碼行數:22,代碼來源:_darwin.py

示例6: _release

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
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 
開發者ID:mass-immersion-approach,項目名稱:MIA-Dictionary-Addon,代碼行數:21,代碼來源:_darwin.py

示例7: __mouse_event

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
def __mouse_event(self, type, x, y):
        mouse_event = Quartz.CGEventCreateMouseEvent(None, type, (x, y), Quartz.kCGMouseButtonLeft)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, mouse_event) 
開發者ID:mayank408,項目名稱:Mousely,代碼行數:5,代碼來源:eye_detection.py

示例8: press

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
def press(self, x, y, button=0):
        event = Quartz.CGEventCreateMouseEvent(None, Mouse.down[button], (x, y), button)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, event) 
開發者ID:mayank408,項目名稱:Mousely,代碼行數:5,代碼來源:eye_detection.py

示例9: release

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
def release(self, x, y, button=0):
        event = Quartz.CGEventCreateMouseEvent(None, Mouse.up[button], (x, y), button)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, event) 
開發者ID:mayank408,項目名稱:Mousely,代碼行數:5,代碼來源:eye_detection.py

示例10: doubleClick

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
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") 
開發者ID:mayank408,項目名稱:Mousely,代碼行數:15,代碼來源:eye_detection.py

示例11: move_rel

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
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) 
開發者ID:mayank408,項目名稱:Mousely,代碼行數:6,代碼來源:eye_detection.py

示例12: _multiClick

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
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) 
開發者ID:asweigart,項目名稱:pyautogui,代碼行數:33,代碼來源:_pyautogui_osx.py

示例13: press

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
def press(x, y, button=1):
        event = Quartz.CGEventCreateMouseEvent(None, pressID[button], (x, y), button - 1)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, event) 
開發者ID:AirtestProject,項目名稱:Poco,代碼行數:5,代碼來源:OSXUIFunc.py

示例14: release

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
def release(x, y, button=1):
        event = Quartz.CGEventCreateMouseEvent(None, releaseID[button], (x, y), button - 1)
        Quartz.CGEventPost(Quartz.kCGHIDEventTap, event) 
開發者ID:AirtestProject,項目名稱:Poco,代碼行數:5,代碼來源:OSXUIFunc.py

示例15: click

# 需要導入模塊: import Quartz [as 別名]
# 或者: from Quartz import CGEventPost [as 別名]
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) 
開發者ID:AirtestProject,項目名稱:Poco,代碼行數:7,代碼來源:OSXUIFunc.py


注:本文中的Quartz.CGEventPost方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。