[Python] python tkinter - detecting arrow keys when an alternate key is pressed

Discussão em 'Python' iniciado por Stack, Outubro 2, 2024.

  1. Stack

    Stack Membro Participativo

    I am using python and tkinter, and wish to capture if an arrow key is pressed, when one of the alternate keys is down.

    I have the following working, for detecting shift, or control, but I can't figure out what the the mask needs to be for detecting if an alternate key is down when an arrow key is pressed.

    if event.keysym == 'space':
    print("space bar")

    if event.state & 0x0001: # shift key
    if event.keysym == 'Down':
    print("shift and down arrow")
    elif event.keysym == 'Up':
    print("shift and up arrow")
    elif event.keysym == 'Left':
    print("shift and left arrow")
    elif event.keysym == 'Right':
    print("shift and right arrow")

    elif event.state & 0x0004: # control key
    if event.keysym == 'Down':
    print("control and down arrow")
    elif event.keysym == 'Up':
    print("control and up arrow")
    elif event.keysym == 'Left':
    print("control and left arrow")
    elif event.keysym == 'Right':
    print("control and right arrow")

    elif event.state & 0x????: # alternate key --- 0x????
    if event.keysym == 'Down':
    print("alternate and down arrow")
    elif event.keysym == 'Up':
    print("alternate and up arrow")
    elif event.keysym == 'Left':
    print("alternate and left arrow")
    elif event.keysym == 'Right':
    print("alternate and right arrow")

    Continue reading...

Compartilhe esta Página