• how can I detect if the shift key is currently down (on windows)(twapi?)

    From et99@et99@rocketship1.me to comp.lang.tcl on Sat Jul 27 17:33:47 2024
    From Newsgroup: comp.lang.tcl

    I want to launch a windows batch job, which then runs a tcl program (passing in the file names dnd'd onto the batch file).

    I would like to also be able to detect if the shift key is currently down in the tcl program. I can't use a normal key binding since the shift key will be pressed (and held) down before the tcl program is launched.

    I asked chatGPT how this can be done, and it said:

    #include <windows.h>

    bool IsShiftKeyDown() {
    return (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0;
    }

    when I asked how to do this with tcl, it said to use a direct windows api call using twapi, and gave this (wrong) answer:

    package require twapi

    proc is_shift_down {} {
    set result [twapi::call user32 GetAsyncKeyState VK_SHIFT]
    return [expr ($result & 0x8000) != 0]
    }


    However, there is mentioned in the twapi docs that one can do a direct call, which this chatGPT example was attempting to do, but unfortunately, the docs says:

    "The Windows API may be directly accessed by Tcl commands that map to Windows functions. This interface is not documented in the TWAPI documentation."

    Assuming the above C code is correct, does anyone know how to use twapi to make that call?

    Or... is there some way that tcl can do it directly?
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Ashok@apnmbx-public@yahoo.com to comp.lang.tcl on Thu Aug 1 10:17:27 2024
    From Newsgroup: comp.lang.tcl

    proc is_shift_down {} {expr {!!([twapi::GetAsyncKeyState 0x10] & 0x8000)}}

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From et99@et99@rocketship1.me to comp.lang.tcl on Thu Aug 1 11:19:38 2024
    From Newsgroup: comp.lang.tcl

    On 7/31/2024 9:47 PM, Ashok wrote:
    proc is_shift_down {} {expr {!!([twapi::GetAsyncKeyState 0x10] & 0x8000)}}>

    Thanks so much for that! I had tried your documentation website, but didn't find it there.

    Ah, I think I see what tbd means now :)











    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From et99@et99@rocketship1.me to comp.lang.tcl on Sat Aug 3 12:11:30 2024
    From Newsgroup: comp.lang.tcl

    On 8/1/2024 11:19 AM, et99 wrote:
    On 7/31/2024 9:47 PM, Ashok wrote:
    proc is_shift_down {} {expr {!!([twapi::GetAsyncKeyState 0x10] & 0x8000)}}>


    I've expanded the above to allow for any key to be tested for up/down and also optionally return the status of the key having been recently pressed, as documented in the windows function GetAsyncKeyState. I've posted the code for this to the wiki here (at the bottom):

    https://wiki.tcl-lang.org/page/KeySyms+on+platforms+other+than+X11



    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Mon Aug 5 08:38:31 2024
    From Newsgroup: comp.lang.tcl

    Am 03.08.2024 um 21:11 schrieb et99:
    On 8/1/2024 11:19 AM, et99 wrote:
    On 7/31/2024 9:47 PM, Ashok wrote:
    proc is_shift_down {} {expr {!!([twapi::GetAsyncKeyState 0x10] &
    0x8000)}}>


    I've expanded the above to allow for any key to be tested for up/down
    and also optionally return the status of the key having been recently pressed, as documented in the windows function GetAsyncKeyState. I've
    posted the code for this to the wiki here (at the bottom):

    https://wiki.tcl-lang.org/page/KeySyms+on+platforms+other+than+X11



    Great work, thank you !
    Maybe provide it to twapi using a ticket there...

    https://sourceforge.net/p/twapi/bugs/

    Tahnks,
    Harald
    --- Synchronet 3.20a-Linux NewsLink 1.114