Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #77: Typo in the code


comp / comp.lang.tcl / Re: how can I detect if the shift key is currently down (on windows) (twapi?)

SubjectAuthor
* how can I detect if the shift key is currently down (on windows) (twapi?)et99
`* Re: how can I detect if the shift key is currently down (on windows) (twapi?)Ashok
 `* Re: how can I detect if the shift key is currently down (on windows) (twapi?)et99
  `* Re: how can I detect if the shift key is currently down (on windows) (twapi?)et99
   `- Re: how can I detect if the shift key is currently down (on windows) (twapi?)Harald Oehlmann

1
Subject: how can I detect if the shift key is currently down (on windows) (twapi?)
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sun, 28 Jul 2024 00:33 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: how can I detect if the shift key is currently down (on windows)
(twapi?)
Date: Sat, 27 Jul 2024 17:33:47 -0700
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <v843lb$3js4c$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 28 Jul 2024 02:33:48 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="47af36ef1a63c69f18f7251a936e268a";
logging-data="3797132"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fl9ikiixXe0ZHzRnETh3/"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:hpix1i1O19Hc685Q4b3BXxY9ENs=
Content-Language: en-US
View all headers

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?

Subject: Re: how can I detect if the shift key is currently down (on windows) (twapi?)
From: Ashok
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 1 Aug 2024 04:47 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: apnmbx-public@yahoo.com (Ashok)
Newsgroups: comp.lang.tcl
Subject: Re: how can I detect if the shift key is currently down (on windows)
(twapi?)
Date: Thu, 1 Aug 2024 10:17:27 +0530
Organization: A noiseless patient Spider
Lines: 2
Message-ID: <v8f40t$20phh$1@dont-email.me>
References: <v843lb$3js4c$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 01 Aug 2024 06:47:26 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2bda159820b2d33853a5311614c60159";
logging-data="2123313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/As55TKK9ANReNt+VYl2On"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:BDniW4Wn7xETy9gWZBK+IgoJzuc=
Content-Language: en-US
In-Reply-To: <v843lb$3js4c$1@dont-email.me>
View all headers

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

Subject: Re: how can I detect if the shift key is currently down (on windows) (twapi?)
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 1 Aug 2024 18:19 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: how can I detect if the shift key is currently down (on windows)
(twapi?)
Date: Thu, 1 Aug 2024 11:19:38 -0700
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <v8gjjs$2am24$1@dont-email.me>
References: <v843lb$3js4c$1@dont-email.me> <v8f40t$20phh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 01 Aug 2024 20:19:40 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="faf8d238b311a7fae381dcd3ce584a21";
logging-data="2447428"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lg0G2LWMcvcdivOOwvA6r"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:7r5ZiZYOwLgRBemBc5L2iSAtztk=
In-Reply-To: <v8f40t$20phh$1@dont-email.me>
Content-Language: en-US
View all headers

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 :)

Subject: Re: how can I detect if the shift key is currently down (on windows) (twapi?)
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sat, 3 Aug 2024 19:11 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: how can I detect if the shift key is currently down (on windows)
(twapi?)
Date: Sat, 3 Aug 2024 12:11:30 -0700
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <v8lvd2$3j5at$1@dont-email.me>
References: <v843lb$3js4c$1@dont-email.me> <v8f40t$20phh$1@dont-email.me>
<v8gjjs$2am24$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 03 Aug 2024 21:11:31 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="6bb8d454eeee5c9a98c2510ac19037d1";
logging-data="3773789"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5ieoJ63myxF1+PbBQeIrv"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:FCKpAGv53jFtAVSJ0Ui5f79KtJg=
In-Reply-To: <v8gjjs$2am24$1@dont-email.me>
Content-Language: en-US
View all headers

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

Subject: Re: how can I detect if the shift key is currently down (on windows) (twapi?)
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Mon, 5 Aug 2024 06:38 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: how can I detect if the shift key is currently down (on windows)
(twapi?)
Date: Mon, 5 Aug 2024 08:38:31 +0200
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <v8ps15$hp4f$1@dont-email.me>
References: <v843lb$3js4c$1@dont-email.me> <v8f40t$20phh$1@dont-email.me>
<v8gjjs$2am24$1@dont-email.me> <v8lvd2$3j5at$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 05 Aug 2024 08:38:29 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ab7993b65a720f14c5758bf871017c08";
logging-data="582799"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IQDRm6Q1cJnthU8guR2/0"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:iZ9Bcw5lTGtwCJh30JbNiwZEWEo=
In-Reply-To: <v8lvd2$3j5at$1@dont-email.me>
Content-Language: en-GB
View all headers

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

1

rocksolid light 0.9.8
clearnet tor