• Problem with 'event generate'

    From Helmut Giese@21:1/5 to All on Thu Jun 2 23:13:18 2022
    Hello out there,
    consider the following script:
    ---
    package require Tk
    set t [text .t -width 40 -height 10]
    pack $t

    # the following line will error out with the message
    # bad event type or keysym "Keypress"
    event generate $t <Keypress> -keysym Return

    event generate $t <KeyPress> -keysym a
    ---
    When I comment the offending line out the following line executes
    (using the same <Keypress> ???) but the 'a' doesn't show up.I must be
    doing something wrong - but what?
    Any help or advice will be greatly appreciated.
    Helmut
    PS: This is with Tcl 8.6.10 on 64 bit Windows 10

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to Helmut Giese on Thu Jun 2 23:20:05 2022
    Helmut Giese <hgiese@ratiosoft.com> schrieb:

    Hello out there,
    consider the following script:
    ---
    package require Tk
    set t [text .t -width 40 -height 10]
    pack $t

    # the following line will error out with the message
    # bad event type or keysym "Keypress"
    event generate $t <Keypress> -keysym Return

    event generate $t <KeyPress> -keysym a
    ---
    When I comment the offending line out the following line executes
    (using the same <Keypress> ???) but the 'a' doesn't show up.I must be
    doing something wrong - but what?
    Any help or advice will be greatly appreciated.
    Helmut
    PS: This is with Tcl 8.6.10 on 64 bit Windows 10
    I just found out that if I change <Keypress> to <KeyPress> it produces
    no error - but no visible result either. Any advice anybody?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From clt.to.davebr@dfgh.net@21:1/5 to All on Fri Jun 3 01:48:37 2022
    PS: This is with Tcl 8.6.10 on 64 bit Windows 10
    I just found out that if I change <Keypress> to <KeyPress> it produces
    no error - but no visible result either. Any advice anybody?

    The binding that inserts a character on a text window is bound to the Text widget class binding tag (Text in this case), not the window binding tag (.t), see

    bindtags .t

    bind Text <KeyPress>

    However

    event generate .t ...

    apparently only sends the event to the window binding tag (.t) so the bindings to the Text tag are not fired. I'm not sure how you might sent an event to other window binding tags.

    You might use the tk::TextInsert command to get the character inserted.

    Dave

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Oehlmann@21:1/5 to All on Fri Jun 3 11:19:33 2022
    Am 02.06.2022 um 23:13 schrieb Helmut Giese:
    Hello out there,
    consider the following script:
    ---
    package require Tk
    set t [text .t -width 40 -height 10]
    pack $t

    # the following line will error out with the message
    # bad event type or keysym "Keypress"
    event generate $t <Keypress> -keysym Return

    event generate $t <KeyPress> -keysym a
    ---
    When I comment the offending line out the following line executes
    (using the same <Keypress> ???) but the 'a' doesn't show up.I must be
    doing something wrong - but what?
    Any help or advice will be greatly appreciated.
    Helmut
    PS: This is with Tcl 8.6.10 on 64 bit Windows 10

    I use:

    event generate $t <KeyPress-Return>
    event generate $t <KeyRelease-Return>

    Maybe, this helps,
    Harald

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From nemethi@21:1/5 to All on Fri Jun 3 15:01:44 2022
    Am 02.06.22 um 23:20 schrieb Helmut Giese:
    Helmut Giese <hgiese@ratiosoft.com> schrieb:

    Hello out there,
    consider the following script:
    ---
    package require Tk
    set t [text .t -width 40 -height 10]
    pack $t

    # the following line will error out with the message
    # bad event type or keysym "Keypress"
    event generate $t <Keypress> -keysym Return

    event generate $t <KeyPress> -keysym a
    ---
    When I comment the offending line out the following line executes
    (using the same <Keypress> ???) but the 'a' doesn't show up.I must be
    doing something wrong - but what?
    Any help or advice will be greatly appreciated.
    Helmut
    PS: This is with Tcl 8.6.10 on 64 bit Windows 10
    I just found out that if I change <Keypress> to <KeyPress> it produces
    no error - but no visible result either. Any advice anybody?

    Like most other things, event names are case-sensitive in Tk. There is
    no event called <Keypress>. OTOH, <KeyPress> is a valid event name and
    may also be written in the abbreviated form <Key>.

    Another problem with your script is that the text widget doesn't have
    the focus. From the description of "event generate" in the "event" man
    page:

    "... Certain events, such as key events, require that the window has
    focus to receive the event properly."

    Note that setting the focus to $t requires more than just invoking
    "focus $t" if the application does not currently have the input focus.
    The following modified version of your script works for me as expected:

    package require Tk
    set t [text .t -width 40 -height 10]
    pack $t

    tkwait visibility $t
    focus -force $t
    event generate $t <KeyPress> -keysym Return
    event generate $t <KeyPress> -keysym a

    The -force option for focus is necessary on Windows but not on Linux (at
    least not on GNOME).

    --
    Csaba Nemethi https://www.nemethi.de mailto:csaba.nemethi@t-online.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerald Lester@21:1/5 to clt.to.davebr@dfgh.net on Fri Jun 3 08:05:17 2022
    On 6/2/22 20:48, clt.to.davebr@dfgh.net wrote:
    PS: This is with Tcl 8.6.10 on 64 bit Windows 10
    I just found out that if I change <Keypress> to <KeyPress> it produces
    no error - but no visible result either. Any advice anybody?

    The binding that inserts a character on a text window is bound to the Text widget class binding tag (Text in this case), not the window binding tag (.t), see

    bindtags .t

    bind Text <KeyPress>

    However

    event generate .t ...

    apparently only sends the event to the window binding tag (.t) so the bindings to the Text tag are not fired. I'm not sure how you might sent an event to other window binding tags.

    You might use the tk::TextInsert command to get the character inserted.

    Ah, are you sure about that. At least on Linux that is not what I see:
    bindtags .t
    .t Text . all
    bind Text
    <Shift-Button-5> <Shift-Button-4> <Button-5> <Button-4>
    <Shift-MouseWheel> <MouseWheel> <B2-Motion> <Button-2> <Control-Key-h> <<TkAccentBackspace>> <<TkClearIMEMarkedText>> <<TkEndIMEMarkedText>> <<TkStartIMEMarkedText>> <Meta-Key-Delete> <Meta-Key-BackSpace> <Meta-Key-greater> <Meta-Key-less> <Meta-Key-f> <Meta-Key-d>
    <Meta-Key-b> <<Redo>> <<Undo>> <Control-Key-t> <Control-Key-o>
    <Control-Key-k> <Control-Key-d> <Key-KP_Enter> <Key-Escape>
    <Control-Key> <Meta-Key> <Alt-Key> <Key> <Key-Insert> <<PasteSelection>> <<Clear>> <<Paste>> <<Copy>> <<Cut>> <<SelectNone>> <<SelectAll>> <Shift-Key-Select> <Control-Shift-Key-space> <Key-Select>
    <Control-Key-space> <Key-BackSpace> <Key-Delete> <Key-Return>
    <Control-Key-i> <Control-Shift-Key-Tab> <Control-Key-Tab>
    <Shift-Key-Tab> <Key-Tab> <Control-Shift-Key-End> <Control-Key-End> <Control-Shift-Key-Home> <Control-Key-Home> <<SelectLineEnd>>
    <<LineEnd>> <<SelectLineStart>> <<LineStart>> <Control-Key-Next> <Control-Key-Prior> <Shift-Key-Next> <Key-Next> <Shift-Key-Prior>
    <Key-Prior> <<SelectNextPara>> <<SelectPrevPara>> <<SelectNextWord>> <<SelectPrevWord>> <<NextPara>> <<PrevPara>> <<NextWord>> <<PrevWord>> <<SelectNextLine>> <<SelectPrevLine>> <<SelectNextChar>>
    <<SelectPrevChar>> <<NextLine>> <<PrevLine>> <<NextChar>> <<PrevChar>> <Control-B1-Motion> <Double-Control-Button-1> <Control-Button-1> <ButtonRelease-1> <B1-Enter> <B1-Leave> <Triple-Shift-Button-1> <Double-Shift-Button-1> <Shift-Button-1> <Triple-Button-1>
    <Double-Button-1> <B1-Motion> <Button-1>


    There is no <KeyPress> event. There is a <Key> event.


    --
    +----------------------------------------------------------------------+
    | Gerald W. Lester, President, KNG Consulting LLC |
    | Email: Gerald.Lester@kng-consulting.net | +----------------------------------------------------------------------+

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to Gerald.Lester@KnG-Consulting.net on Fri Jun 3 08:30:02 2022
    At Fri, 3 Jun 2022 08:05:17 -0500 Gerald Lester <Gerald.Lester@KnG-Consulting.net> wrote:


    On 6/2/22 20:48, clt.to.davebr@dfgh.net wrote:
    PS: This is with Tcl 8.6.10 on 64 bit Windows 10
    I just found out that if I change <Keypress> to <KeyPress> it produces
    no error - but no visible result either. Any advice anybody?

    The binding that inserts a character on a text window is bound to the Text widget class binding tag (Text in this case), not the window binding tag (.t), see

    bindtags .t

    bind Text <KeyPress>

    However

    event generate .t ...

    apparently only sends the event to the window binding tag (.t) so the bindings to the Text tag are not fired. I'm not sure how you might sent an event to other window binding tags.

    You might use the tk::TextInsert command to get the character inserted.

    Ah, are you sure about that. At least on Linux that is not what I see:
    bindtags .t
    .t Text . all
    bind Text
    <Shift-Button-5> <Shift-Button-4> <Button-5> <Button-4>
    <Shift-MouseWheel> <MouseWheel> <B2-Motion> <Button-2> <Control-Key-h> <<TkAccentBackspace>> <<TkClearIMEMarkedText>> <<TkEndIMEMarkedText>> <<TkStartIMEMarkedText>> <Meta-Key-Delete> <Meta-Key-BackSpace> <Meta-Key-greater> <Meta-Key-less> <Meta-Key-f> <Meta-Key-d>
    <Meta-Key-b> <<Redo>> <<Undo>> <Control-Key-t> <Control-Key-o> <Control-Key-k> <Control-Key-d> <Key-KP_Enter> <Key-Escape>
    <Control-Key> <Meta-Key> <Alt-Key> <Key> <Key-Insert> <<PasteSelection>> <<Clear>> <<Paste>> <<Copy>> <<Cut>> <<SelectNone>> <<SelectAll>> <Shift-Key-Select> <Control-Shift-Key-space> <Key-Select>
    <Control-Key-space> <Key-BackSpace> <Key-Delete> <Key-Return>
    <Control-Key-i> <Control-Shift-Key-Tab> <Control-Key-Tab>
    <Shift-Key-Tab> <Key-Tab> <Control-Shift-Key-End> <Control-Key-End> <Control-Shift-Key-Home> <Control-Key-Home> <<SelectLineEnd>>
    <<LineEnd>> <<SelectLineStart>> <<LineStart>> <Control-Key-Next> <Control-Key-Prior> <Shift-Key-Next> <Key-Next> <Shift-Key-Prior>
    <Key-Prior> <<SelectNextPara>> <<SelectPrevPara>> <<SelectNextWord>> <<SelectPrevWord>> <<NextPara>> <<PrevPara>> <<NextWord>> <<PrevWord>> <<SelectNextLine>> <<SelectPrevLine>> <<SelectNextChar>>
    <<SelectPrevChar>> <<NextLine>> <<PrevLine>> <<NextChar>> <<PrevChar>> <Control-B1-Motion> <Double-Control-Button-1> <Control-Button-1> <ButtonRelease-1> <B1-Enter> <B1-Leave> <Triple-Shift-Button-1> <Double-Shift-Button-1> <Shift-Button-1> <Triple-Button-1>
    <Double-Button-1> <B1-Motion> <Button-1>


    There is no <KeyPress> event. There is a <Key> event.

    From man 3tk bind:


    EVENT TYPES
    The type field may be any of the standard X event types, with a few ex‐
    tra abbreviations. The type field will also accept a couple non-stan‐
    dard X event types that were added to better support the Macintosh and
    Windows platforms. Below is a list of all the valid types; where two
    names appear together, they are synonyms.

    Activate Destroy Map
    ButtonPress, Button Enter MapRequest
    ButtonRelease Expose Motion
    Circulate FocusIn MouseWheel
    CirculateRequest FocusOut Property
    Colormap Gravity Reparent
    Configure KeyPress, Key ResizeRequest
    ConfigureRequest KeyRelease Unmap
    Create Leave Visibility
    Deactivate






    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From clt.to.davebr@dfgh.net@21:1/5 to All on Fri Jun 3 14:03:00 2022
    From: Robert Heller <heller@deepsoft.com>
    Date: Fri Jun 03 13:30:02 GMT 2022
    Subject: Problem with 'event generate'


    There is no <KeyPress> event. There is a <Key> event.

    From man 3tk bind:


    EVENT TYPES

    Configure KeyPress, Key ResizeRequest

    It appears <Key> and <KeyPress> are synonyms. In the rest of the man page text only KeyPress is mentioned. However:

    bind Text

    returns only <Key> in the list.

    bind Text <KeyPress>

    and

    bind Text <Key>

    both return the same script, and changing either script changes both.

    It appears the shorter event name is returned in this case

    Dave B

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Mon Jun 6 17:59:06 2022
    Hello everybody,
    sorry for the delay - I was offline over the weekend.
    I want to thank everyone who responded. Eventually I went with the
    solution posted by Csaba.
    Thanks again and best regards
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)