how can I detect if the shift key is currently down (on windows) (twapi
From
et99@21:1/5 to
All on Sat Jul 27 17:33:47 2024
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?
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)