StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Rob Otter  
#1 Posted : Wednesday, December 23, 2020 9:43:26 PM(UTC)
Rob Otter

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 10/26/2020(UTC)
Posts: 50
Germany
Location: Darmstadt

Thanks: 15 times
Was thanked: 2 time(s) in 2 post(s)
I´ve spent hours on this... Blink

I wanted to develop a script for a hotkey and discovered this weird problem:
It is not possible to copy a text selection into clipboard (tried SendKeys and SendModifiedVKeys). When pressing the hotkey, the copy command is not executed but instead some other character seems to be sent: i.e. in Firefox the developer tools are opened as if I had pressed F12, in the S+ script editor, selected text is replaced by a control character "ETX" (End-of-text). Other commands like ^v or ^x are also not working but with other effects.

I tried various hotkeys (with and without Ctrl, Alt, Shift; F-Keys, normal keys etc), they all produce the same wrong result with Send(ModifiedV)Keys if Ctrl key is to be sent.
It doesn´t matter if KeyboardHook is enabled or not. Strange enough, this only applies to hotkeys, not gestures - the latter are working fine.

So, why is this not working and how can I get around that? Is there another function to put selected text into the clipboard?
Rob  
#2 Posted : Wednesday, December 23, 2020 11:33:58 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Out to eat dinner, but do you have The culture set to English? Also, try as an unregistered hotkey and let me know.
Rob Otter  
#3 Posted : Thursday, December 24, 2020 5:21:44 AM(UTC)
Rob Otter

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 10/26/2020(UTC)
Posts: 50
Germany
Location: Darmstadt

Thanks: 15 times
Was thanked: 2 time(s) in 2 post(s)
Yes, culture is english, but I also tried german - same result. Nevertheless, I am working on a german Windows but I doubt this will be the root cause.
I don´t expect (or need) a solution quite soon these days - just have a nice, relaxing and healthy christmas!
Rob  
#4 Posted : Thursday, December 24, 2020 7:14:39 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Let me know if unregistered hotkey does the same thing. Also try a long sleep before sending the keys, just to see if there's any conflict with you still pressing the hotkey.

Have a merry Christmas as well!
Rob Otter  
#5 Posted : Thursday, December 24, 2020 7:50:40 AM(UTC)
Rob Otter

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 10/26/2020(UTC)
Posts: 50
Germany
Location: Darmstadt

Thanks: 15 times
Was thanked: 2 time(s) in 2 post(s)
Sorry, I forgot to mention that "Unregistered" and/or "Consume" doesn´t have any effect - but adding a delay of at least 200ms did the trick! To be more specific, the problem occurs if the hotkey is still pressed when the SendKey command is fired. Adding the delay time only works if it is long enough to ensure that the hotkey is released early enough.
It seems like pressing the real key and sending a virtual key at the same time is the problem. Don´t know if this can be fixed easily but I would envision two options:
1) Real & virtual key presses are queued so they will not occur at the same time.
2) A hotkey definition is fired when the hotkey is _released_ - ok, instead, this might not be intended and might destroy wished functionality. In that case, maybe a switchable option per hotkey (fire on press / release) would be better

Kind regards,
Rob Otter
Rob Otter  
#6 Posted : Thursday, December 24, 2020 9:54:37 AM(UTC)
Rob Otter

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 10/26/2020(UTC)
Posts: 50
Germany
Location: Darmstadt

Thanks: 15 times
Was thanked: 2 time(s) in 2 post(s)
For now, I get around the issue with this code instead of a sp.Delay(500) right before the SendKey command:

Code:
// Avoid race condition with hotkey press:
while (sp.GetKeyState(vk.SHIFT)) {
    sp.Delay(50);
}

Strange enough, this also works if the hotkey doesn´t contain the Shift modifier...
Rob  
#7 Posted : Thursday, December 24, 2020 10:05:34 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Have you tried sending the hotkey modifier (e.g. Control) up in the script?

On my phone so can't see exact method, but something like so.SendVKeyUp(vk.LCONTROL).

That should resolve the issue and not involve the timing.

Windows controls when the hotkey is recognized (for registered hotkeys), and there are just a lot of possible variables to queueing up the keys. If sending the key up solves it, that will probably be the end of it for now.

Another option could be to use GetKeyState in the script to wait until the offending key is no longer being held.

Edit: was typing this up when you were responding

Edited by user Thursday, December 24, 2020 10:07:48 AM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.