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

Liste des GroupesRevenir à cl tcl 
Sujet : how can I detect if the shift key is currently down (on windows) (twapi?)
De : et99 (at) *nospam* rocketship1.me (et99)
Groupes : comp.lang.tcl
Date : 28. Jul 2024, 01:33:47
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v843lb$3js4c$1@dont-email.me>
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1
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?

Date Sujet#  Auteur
28 Jul 24 * how can I detect if the shift key is currently down (on windows) (twapi?)5et99
1 Aug 24 `* Re: how can I detect if the shift key is currently down (on windows) (twapi?)4Ashok
1 Aug 24  `* Re: how can I detect if the shift key is currently down (on windows) (twapi?)3et99
3 Aug 24   `* Re: how can I detect if the shift key is currently down (on windows) (twapi?)2et99
5 Aug 24    `- Re: how can I detect if the shift key is currently down (on windows) (twapi?)1Harald Oehlmann

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal