• How to simulate a 'shift click'

    From Helmut Giese@hgiese@ratiosoft.com to comp.lang.tcl on Sun Aug 25 17:55:07 2024
    From Newsgroup: comp.lang.tcl

    Hello out there,
    I can simulate a simple click but fail at a 'shift click'.
    Below is what I tried:
    ---
    package require Tk
    foreach ch [winfo children "."] {destroy $ch}

    # create a test app
    set btn [ttk::button .btn -text "Press me"]
    pack $btn
    # add some bindings
    bind $btn <Button-1> {puts "Simple click"}
    bind $btn <Shift-Button-1> {puts "Shift click"}

    focus $btn
    set x [winfo x $btn] ; set y [winfo y $btn]
    # place the mouse
    event generate "." <Motion> -x [incr x 50] -y [incr y 10] -warp 1

    event generate $btn <ButtonPress-1>
    after 100 ; event generate $btn <ButtonRelease-1>

    # now a 'shift click'
    if 1 {
    event generate $btn <KeyPress> -keysym Shift_L
    } else {
    event generate $btn <Key-Shift_L>
    }
    event generate $btn <ButtonPress-1>
    after 100 ; event generate $btn <ButtonRelease-1>
    event generate $btn <KeyRelease> -keysym Shift_L
    ---
    All I ever get is twice 'Simple click' - no matter whether I use
    <Key-Shift_L> or the longer form, wether I generate the keypress for
    $btn or ".". I am out of ideas what to try next.
    Any help will be greatly appreciated
    Helmut.
    PS: This is on Windows with Tcl 8.6.10
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Ian@gay@sfuu.ca to comp.lang.tcl on Sun Aug 25 09:11:31 2024
    From Newsgroup: comp.lang.tcl

    Helmut Giese wrote:

    Hello out there,
    I can simulate a simple click but fail at a 'shift click'.
    Below is what I tried:
    ---
    package require Tk
    foreach ch [winfo children "."] {destroy $ch}

    # create a test app
    set btn [ttk::button .btn -text "Press me"]
    pack $btn
    # add some bindings
    bind $btn <Button-1> {puts "Simple click"}
    bind $btn <Shift-Button-1> {puts "Shift click"}

    focus $btn
    set x [winfo x $btn] ; set y [winfo y $btn]
    # place the mouse
    event generate "." <Motion> -x [incr x 50] -y [incr y 10] -warp 1

    event generate $btn <ButtonPress-1>
    after 100 ; event generate $btn <ButtonRelease-1>

    # now a 'shift click'
    if 1 {
    event generate $btn <KeyPress> -keysym Shift_L
    } else {
    event generate $btn <Key-Shift_L>
    }
    event generate $btn <ButtonPress-1>
    after 100 ; event generate $btn <ButtonRelease-1>
    event generate $btn <KeyRelease> -keysym Shift_L
    ---
    All I ever get is twice 'Simple click' - no matter whether I use <Key-Shift_L> or the longer form, wether I generate the keypress for
    $btn or ".". I am out of ideas what to try next.
    Any help will be greatly appreciated
    Helmut.
    PS: This is on Windows with Tcl 8.6.10

    Have you tried using the -state parameter to event generate?
    --
    *********** To reply by e-mail, make w single in address **************
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Helmut Giese@hgiese@ratiosoft.com to comp.lang.tcl on Sun Aug 25 20:24:18 2024
    From Newsgroup: comp.lang.tcl

    Hello Ian,

    Have you tried using the -state parameter to event generate?

    yeah, that did the trick. You're a genius :), many thanks
    Helmut
    --- Synchronet 3.20a-Linux NewsLink 1.114