def win_message_to_event(message, target = None):
    hwnd, msg, wParam, lParam, milliseconds, gpos = message
    kind, button = win_message_map[msg]
    time = milliseconds / 1000.0
    if kind == 'mouse_move' and wParam & win_button_flags <> 0:
        kind = 'mouse_drag'
    if target:
        lpos = target.global_to_local(gpos)
    else:
        lpos = gpos
    event = Event()
    event.kind = kind
    event.global_position = gpos
    event.position = lpos
    event.time = time
    event.button = button
    shift = api.GetKeyState(wc.VK_SHIFT) & 0x80 <> 0
    control = api.GetKeyState(wc.VK_CONTROL) & 0x80 <> 0
    option = api.GetKeyState(wc.VK_MENU) & 0x80 <> 0
    event.shift = event.extend_contig = shift
    event.control = event.extend_noncontig = control
    event.option = option
    vkey = None
    if kind == 'mouse_down':
        global win_last_mouse_down
        last = win_last_mouse_down
        if last and last.button == button and time - last.time <= win_dbl_time:
            x0, y0 = last.global_position
            x1, y1 = gpos
            if abs(x1 - x0) <= win_dbl_xdist and abs(y1 - y0) <= win_dbl_ydist:
                event.num_clicks = last.num_clicks + 1
        win_last_mouse_down = event
    elif kind == 'key_down' or kind == 'key_up':
        event.unichars = ui.TranslateVirtualKey(wParam)
        event.char = event.unichars.decode('ascii')
        event._keycode = wParam
        if wParam == 0x0d:
            if (lParam & 0x1000000):
                event.key = 'enter'
            else:
                event.key = 'return'
        else:
            event.key = win_special_keys.get(wParam) or event.char
        if kind == 'key_down':
            event.auto = lParam & win_prev_key_state <> 0
    return event
Example #2
0
def win_message_to_event(message, target=None):
    hwnd, msg, wParam, lParam, milliseconds, gpos = message
    kind, button = win_message_map[msg]
    time = milliseconds / 1000.0
    if kind == 'mouse_move' and wParam & win_button_flags <> 0:
        kind = 'mouse_drag'
    if target:
        lpos = target.global_to_local(gpos)
    else:
        lpos = gpos
    event = Event()
    event.kind = kind
    event.global_position = gpos
    event.position = lpos
    event.time = time
    event.button = button
    shift = api.GetKeyState(wc.VK_SHIFT) & 0x80 <> 0
    control = api.GetKeyState(wc.VK_CONTROL) & 0x80 <> 0
    option = api.GetKeyState(wc.VK_MENU) & 0x80 <> 0
    event.shift = event.extend_contig = shift
    event.control = event.extend_noncontig = control
    event.option = option
    vkey = None
    if kind == 'mouse_down':
        global win_last_mouse_down
        last = win_last_mouse_down
        if last and last.button == button and time - last.time <= win_dbl_time:
            x0, y0 = last.global_position
            x1, y1 = gpos
            if abs(x1 - x0) <= win_dbl_xdist and abs(y1 - y0) <= win_dbl_ydist:
                event.num_clicks = last.num_clicks + 1
        win_last_mouse_down = event
    elif kind == 'key_down' or kind == 'key_up':
        event.unichars = ui.TranslateVirtualKey(wParam)
        event.char = event.unichars.decode('ascii')
        event._keycode = wParam
        if wParam == 0x0d:
            if (lParam & 0x1000000):
                event.key = 'enter'
            else:
                event.key = 'return'
        else:
            event.key = win_special_keys.get(wParam) or event.char
        if kind == 'key_down':
            event.auto = lParam & win_prev_key_state <> 0
    return event