• Unable to windows cursor to focus on entry box

    From The Rickster@21:1/5 to All on Tue Aug 29 22:12:02 2023
    There is a windows speech application that is invoked with the Win key + h. Thanks to greg and others, it can be done programmatically. However the focus must be on an entry box so that the spoken text may be placed there. However, what happens is that
    when the .tcl script is selected in explorer, the cursor remains over the .tcl file and the code gets invoked twice. So, it seems that focus is not moved away and the mouse down invokes it a second time. I thought focusmodel and focus would make what was
    needed happen.
    The twapi mouse down has to occur in the entry box.
    (by the way, if I\we can get this working then there is a way to use azure speech for $0)

    The tcl code is -
    package require twapi

    set SRStatement {}
    wm iconify .
    console hide

    set top [toplevel .t1 -background {light blue}]
    set theLabel [label $top.l1 -text {hello joe}]
    set theEntryBox [ttk::entry $top.e1 -textvariable SRStatement -width 20 -font {{Segoe UI bold} 10}]
    set theExit [ttk::button $top.b1 -text Close -command {destroy . $top ; exit}]

    pack $theLabel $theEntryBox $theExit -side top -pady 16

    wm focusmodel $top active
    tkwait visibility $top
    focus $theEntryBox
    update
    # make the mouse selection to indicate the text entry location for speech rec output
    ::twapi::click_mouse_button right

    ::twapi::send_input {"keydown 0x5B 0" "key 0x48 0" "keyup 0x5B 0"}

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Rickster@21:1/5 to All on Tue Aug 29 22:30:10 2023
    I just tried preceding the mouse down with twapi::move_mouse to reposition it and it worked. However, then what is the purpose of focus??

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Oehlmann@21:1/5 to All on Wed Aug 30 11:57:17 2023
    Am 30.08.2023 um 07:30 schrieb The Rickster:
    I just tried preceding the mouse down with twapi::move_mouse to reposition it and it worked. However, then what is the purpose of focus??

    You may convince Windows that your application should be at front and
    not Windows Explorer.

    You may try:

    raise .
    focus .entry
    update
    Send Win+H

    Take care,
    Harald

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to The Rickster on Wed Aug 30 13:22:58 2023
    The Rickster <sled99dog@gmail.com> wrote:
    I just tried preceding the mouse down with twapi::move_mouse to
    reposition it and it worked. However, then what is the purpose of
    focus??

    You are conflating mouse position and focus. Those are two different
    items, and the only connection between them is that most GUI's shift
    the focus automatically based upon where the mouse is positioned when a
    click occurs.

    Beyond that, they are different. Mouse position is where the mouse is presently positioned, and focus is which UI element receives keyboard
    input when a user types.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From greg@21:1/5 to The Rickster on Wed Aug 30 11:36:38 2023
    The Rickster schrieb am Mittwoch, 30. August 2023 um 07:12:06 UTC+2:
    There is a windows speech application that is invoked with the Win key + h. Thanks to greg and others, it can be done programmatically. However the focus must be on an entry box so that the spoken text may be placed there. However, what happens is that
    when the .tcl script is selected in explorer, the cursor remains over the .tcl file and the code gets invoked twice. So, it seems that focus is not moved away and the mouse down invokes it a second time. I thought focusmodel and focus would make what was
    needed happen.
    The twapi mouse down has to occur in the entry box.
    (by the way, if I\we can get this working then there is a way to use azure speech for $0)

    The tcl code is -
    package require twapi

    set SRStatement {}
    wm iconify .
    console hide

    set top [toplevel .t1 -background {light blue}]
    set theLabel [label $top.l1 -text {hello joe}]
    set theEntryBox [ttk::entry $top.e1 -textvariable SRStatement -width 20 -font {{Segoe UI bold} 10}]
    set theExit [ttk::button $top.b1 -text Close -command {destroy . $top ; exit}]

    pack $theLabel $theEntryBox $theExit -side top -pady 16

    wm focusmodel $top active
    tkwait visibility $top
    focus $theEntryBox
    update
    # make the mouse selection to indicate the text entry location for speech rec output
    ::twapi::click_mouse_button right

    ::twapi::send_input {"keydown 0x5B 0" "key 0x48 0" "keyup 0x5B 0"}


    #https://twapi.magicsplat.com/v4.7/ui.html#tkpath_to_hwnd #https://twapi.magicsplat.com/v4.7/ui.html#set_focus

    ...
    twapi::set_focus [twapi::tkpath_to_hwnd $theEntryBox]
    ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Rickster@21:1/5 to greg on Thu Aug 31 13:28:37 2023
    On Wednesday, August 30, 2023 at 11:36:41 AM UTC-7, greg wrote:
    The Rickster schrieb am Mittwoch, 30. August 2023 um 07:12:06 UTC+2:
    There is a windows speech application that is invoked with the Win key + h. Thanks to greg and others, it can be done programmatically. However the focus must be on an entry box so that the spoken text may be placed there. However, what happens is
    that when the .tcl script is selected in explorer, the cursor remains over the .tcl file and the code gets invoked twice. So, it seems that focus is not moved away and the mouse down invokes it a second time. I thought focusmodel and focus would make
    what was needed happen.
    The twapi mouse down has to occur in the entry box.
    (by the way, if I\we can get this working then there is a way to use azure speech for $0)

    The tcl code is -
    package require twapi

    set SRStatement {}
    wm iconify .
    console hide

    set top [toplevel .t1 -background {light blue}]
    set theLabel [label $top.l1 -text {hello joe}]
    set theEntryBox [ttk::entry $top.e1 -textvariable SRStatement -width 20 -font {{Segoe UI bold} 10}]
    set theExit [ttk::button $top.b1 -text Close -command {destroy . $top ; exit}]

    pack $theLabel $theEntryBox $theExit -side top -pady 16

    wm focusmodel $top active
    tkwait visibility $top
    focus $theEntryBox
    update
    # make the mouse selection to indicate the text entry location for speech rec output
    ::twapi::click_mouse_button right

    ::twapi::send_input {"keydown 0x5B 0" "key 0x48 0" "keyup 0x5B 0"}
    #https://twapi.magicsplat.com/v4.7/ui.html#tkpath_to_hwnd #https://twapi.magicsplat.com/v4.7/ui.html#set_focus

    ...
    twapi::set_focus [twapi::tkpath_to_hwnd $theEntryBox]
    ...
    Thanks ... was moving in that direction (pardon the pun). But seeing how you wrote it gives confidence. Think biggest cerebral issue was pointed out by Rich, Needed to separate Windows from TK.
    Thanks again...and for what it is worth, this is a way to use\try out Azure speech rec (NOT VOICE REC, as many call it! {;-) )

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Rickster@21:1/5 to The Rickster on Fri Sep 1 19:37:17 2023
    On Thursday, August 31, 2023 at 1:28:41 PM UTC-7, The Rickster wrote:
    On Wednesday, August 30, 2023 at 11:36:41 AM UTC-7, greg wrote:
    The Rickster schrieb am Mittwoch, 30. August 2023 um 07:12:06 UTC+2:
    There is a windows speech application that is invoked with the Win key + h. Thanks to greg and others, it can be done programmatically. However the focus must be on an entry box so that the spoken text may be placed there. However, what happens is
    that when the .tcl script is selected in explorer, the cursor remains over the .tcl file and the code gets invoked twice. So, it seems that focus is not moved away and the mouse down invokes it a second time. I thought focusmodel and focus would make
    what was needed happen.
    The twapi mouse down has to occur in the entry box.
    (by the way, if I\we can get this working then there is a way to use azure speech for $0)

    The tcl code is -
    package require twapi

    set SRStatement {}
    wm iconify .
    console hide

    set top [toplevel .t1 -background {light blue}]
    set theLabel [label $top.l1 -text {hello joe}]
    set theEntryBox [ttk::entry $top.e1 -textvariable SRStatement -width 20 -font {{Segoe UI bold} 10}]
    set theExit [ttk::button $top.b1 -text Close -command {destroy . $top ; exit}]

    pack $theLabel $theEntryBox $theExit -side top -pady 16

    wm focusmodel $top active
    tkwait visibility $top
    focus $theEntryBox
    update
    # make the mouse selection to indicate the text entry location for speech rec output
    ::twapi::click_mouse_button right

    ::twapi::send_input {"keydown 0x5B 0" "key 0x48 0" "keyup 0x5B 0"}
    #https://twapi.magicsplat.com/v4.7/ui.html#tkpath_to_hwnd #https://twapi.magicsplat.com/v4.7/ui.html#set_focus

    ...
    twapi::set_focus [twapi::tkpath_to_hwnd $theEntryBox]
    ...
    Thanks ... was moving in that direction (pardon the pun). But seeing how you wrote it gives confidence. Think biggest cerebral issue was pointed out by Rich, Needed to separate Windows from TK.
    Thanks again...and for what it is worth, this is a way to use\try out Azure speech rec (NOT VOICE REC, as many call it! {;-) )
    Turns out, only solution is to use winfo to locate position of entry box, adjusted for screen location of toplevel, then use twapi to move the windows cursor accordingly. Next twapi click_mouse_button was used to effect physical, windows focus and,
    finally, invoke MS VoiceType with twapi send_input.

    Appreciate all of the help getting this solution. Going to open another discussion on behavior of entry.

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