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

Notification

Icon
Error

Options
Go to last post Go to first unread
Kief  
#1 Posted : Friday, September 10, 2021 2:32:15 AM(UTC)
Kief

Rank: Member

Reputation:

Groups: Approved
Joined: 9/5/2021(UTC)
Posts: 13
United Kingdom

Thanks: 7 times
Is it possible to send a keyboard shortcut by pressing a different key/combo? No mouse involved?

ie. When I press backslash "\", it sends "CTRL+L", but only when a certain app has focus.
Rob  
#2 Posted : Friday, September 10, 2021 2:50:07 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 22 times
Was thanked: 309 time(s) in 270 post(s)
You can make a hotkey which is Unregistered and check Consume, then in the hotkey script, check the sp.ForegroundWindow() and send "\" or "CTRL+L" depending on the active window.
thanks 1 user thanked Rob for this useful post.
Kief on 9/10/2021(UTC)
Kief  
#3 Posted : Friday, September 10, 2021 3:01:19 PM(UTC)
Kief

Rank: Member

Reputation:

Groups: Approved
Joined: 9/5/2021(UTC)
Posts: 13
United Kingdom

Thanks: 7 times
Brilliant!

I just have to say How happy I am to have found this amazing tool. I couldn't uninstall my browser gesture extensions fast enough. and to handle all my shortcut needs too, with c# script.

This tool is more than a dream come true. Thank you for making this. <3

Edited by user Friday, September 10, 2021 3:08:48 PM(UTC)  | Reason: Not specified

Kief  
#4 Posted : Friday, September 10, 2021 3:47:02 PM(UTC)
Kief

Rank: Member

Reputation:

Groups: Approved
Joined: 9/5/2021(UTC)
Posts: 13
United Kingdom

Thanks: 7 times
Oh wait. it isn't C#. I presumed it was when I saw .NET

Since the app title changes depending on project. I was hoping to do something like:
Code:
if( title.Contains("Ableton") ){

}
Guess I need to go study jscript.

Edited by user Friday, September 10, 2021 3:52:46 PM(UTC)  | Reason: Not specified

Rob  
#5 Posted : Friday, September 10, 2021 3:56:05 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 22 times
Was thanked: 309 time(s) in 270 post(s)
There's a lot of interop, so sometimes you'll be accessing C#/.NET properties/methods, but it's all being managed by ClearScript - which runs in the Chrome V8 JavaScript engine.

So in this case, you'd use the javascript includes:
Code:
if( title.includes("Ableton") ){

}
thanks 1 user thanked Rob for this useful post.
Kief on 9/10/2021(UTC)
Kief  
#6 Posted : Friday, September 10, 2021 3:56:06 PM(UTC)
Kief

Rank: Member

Reputation:

Groups: Approved
Joined: 9/5/2021(UTC)
Posts: 13
United Kingdom

Thanks: 7 times
It is a little strange that I can post to the thread without moderation, but if I notice a typo and edit the post, then the edit must await moderation.
Kief  
#7 Posted : Friday, September 10, 2021 4:18:43 PM(UTC)
Kief

Rank: Member

Reputation:

Groups: Approved
Joined: 9/5/2021(UTC)
Posts: 13
United Kingdom

Thanks: 7 times
I did the thing you mentioned in another thread about getting the wndTitle in Global, and that appears to be detecting Ableton correctly.

Global:

UserPostedImage


When I press the backslash key in the Hotkey box, it detects it as "OEM_5", but pressing it elsewhere does not seem to trigger the script. not even to post an error in the console.

UserPostedImage

I do notice there is this orange Warning type icon on the Hotkey list entry.

Steps tab is empty. Does something need to be there to call the script?

Edited by user Friday, September 10, 2021 4:26:12 PM(UTC)  | Reason: Not specified

Kief  
#8 Posted : Friday, September 10, 2021 4:34:22 PM(UTC)
Kief

Rank: Member

Reputation:

Groups: Approved
Joined: 9/5/2021(UTC)
Posts: 13
United Kingdom

Thanks: 7 times
I got it working!
Code:
StrokesPlus.Console.Log(wndTitle);
if(wndTitle.includes("Ableton")){
    StrokesPlus.Console.Log("Ableton: True");
    sp.SendKeys("^l");
}else{
    StrokesPlus.Console.Log("Ableton: False");
    sp.SendVKey(vk.OEM_5);
}
Just by changing the else sendkey from "\" to vk.OEM_5 Blink

That seems very odd to me. The warning icon is still there too. but it works. so I won't question any of these peculiarities. :D

I just noticed the StrokesPlus.Console.Log(wndTitle); isn't working here too.

Edited by user Friday, September 10, 2021 4:36:42 PM(UTC)  | Reason: Not specified

Rob  
#9 Posted : Friday, September 10, 2021 5:15:59 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 22 times
Was thanked: 309 time(s) in 270 post(s)
I've bumped up your reputation, always be fighting spammers/bots!

The color is just to signify it's unregistered, versus a registered hotkey (green).

Regarding the wndTitle thing, I see you're defining it in the foreground window change, but there are multiple script engines, each with their own scope. So it's possible wndTitle doesn't exist when the hotkey script is being executed.

Re: SendKeys - that's Microsoft's SendKeys and honestly it has peculiarities. I generally recommend using the SendV* methods for more explicit control.
thanks 1 user thanked Rob for this useful post.
Kief on 9/10/2021(UTC)
Rob  
#10 Posted : Friday, September 10, 2021 5:21:28 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 22 times
Was thanked: 309 time(s) in 270 post(s)
You can store values for globals between script engines:
StrokesPlus.StoredValues.Strings.Get/Set


You can also access a specific script engine's global scope like:

StrokesPlus.ScriptEngine.List[0].Engine.Script.wndTitle = "test";
or
StrokesPlus.ScriptEngine.List.First().Engine.Script.wndTitle = "test";

However, script engines are volatile and are reloaded when the settings window Apply/OK are clicked and under other circumstances, where the stored variables are process scoped and stay until S+ exists or they are manually cleared.
thanks 1 user thanked Rob for this useful post.
Kief on 9/10/2021(UTC)
Kief  
#11 Posted : Friday, September 10, 2021 5:37:01 PM(UTC)
Kief

Rank: Member

Reputation:

Groups: Approved
Joined: 9/5/2021(UTC)
Posts: 13
United Kingdom

Thanks: 7 times
Thank you. I am what some may call an edit freak. I don't think anyone ever has. but they could.


"wndTitle" does appear to be global. The Console log wasn't printing previously because SendKey didn't like "\", which somehow was not allowing any part of the script to run. After fixing that, the console log is now printing correctly.

So, a SyntaxError without a ScriptEngineException?

Thanks for the extra scope info. :)

Edited by user Friday, September 10, 2021 5:39:25 PM(UTC)  | Reason: Not specified

Rob  
#12 Posted : Friday, September 10, 2021 9:09:17 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 22 times
Was thanked: 309 time(s) in 270 post(s)
Oh right, backslashes are escape characters... can't believe I didn't think about that!
thanks 1 user thanked Rob for this useful post.
Kief on 9/13/2021(UTC)
Kief  
#13 Posted : Monday, September 13, 2021 3:02:16 PM(UTC)
Kief

Rank: Member

Reputation:

Groups: Approved
Joined: 9/5/2021(UTC)
Posts: 13
United Kingdom

Thanks: 7 times
Actually. I did run into what appears to be a scope issue.

wndTitle was available at the beginning of the script when printed by Console.log, but not within the proceeding if-else block. Which was silently being voided due to wndTitle==null I guess. After moving the focus detection into the same script. the if-else block suddenly sprang to life.

The really strange thing is that it was working when I first created it. but today it wasn't.

example:
Code:
StrokesPlus.Console.Log(wndTitle); // wndTitle != null
if (wndTitle.includes("Bitwig")) // wndTitle == null
{
    // Will never execute
}
else
{
    // Neither will this
}
Are these the different script engines you were referring to?

New version:
Code:
if(sp.ForegroundWindow().Title.startsWith("Bitwig Studio - "))
{
    sp.SendVKeyDown(vk.CONTROL);
    sp.SendVKey(vk.VK_L);
    sp.SendVKeyUp(vk.CONTROL);
}
else
{
    sp.SendVKey(vk.OEM_5);
}
Does this look like best practice?

Also:
I'm fairly certain this wasn't happening before, but now when I press the "Apply" or "OK" buttons, it disables StrokesPlus. ie. the system tray icon turns grey, and I have to click it to re-enable. Nothing is printed in the console when this occurs. Is this an indication of misconfiguration or is this standard behaviour that I was somehow not triggering before? I wouldn't rule out the possibility that this is something I did by messing with options.
Edit: This was an anomaly that I can no longer reproduce after closing/re-opening GUI.

I removed "Control" from the "Ignore Key" options. I'm not entirely sure why that was enabled by default, but I thought it might have something to do with Mac's using Ctrl as a mouse button modifier? I presumed that if it was a problem. it would quickly become apparent, but so far no proof of it's necessity has been revealed.

Edited by user Monday, September 13, 2021 3:58:48 PM(UTC)  | Reason: Clarify that the else statement is also voided in the null scope example and altered the sp disablin

Kief  
#14 Posted : Monday, September 13, 2021 5:35:32 PM(UTC)
Kief

Rank: Member

Reputation:

Groups: Approved
Joined: 9/5/2021(UTC)
Posts: 13
United Kingdom

Thanks: 7 times
I am now experiencing another issue. I can't say if this is App specific (in this case Ableton)

UserPostedImage

If I use "Alt + SPACE" as a Hotkey trigger, when it fires "sp.SendVKey(vk.HOME);" Because I am still holding Alt, it adds it to the SendVKey, so what is actually being sent is "Alt + HOME".

Any way to truly consume the Alt so it can't modify the SendVKey?

Or maybe make the SendVKey() wait until I've released Alt?

Edited by user Monday, September 13, 2021 5:42:09 PM(UTC)  | Reason: Illustrated image

Rob  
#15 Posted : Monday, September 13, 2021 6:05:24 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 22 times
Was thanked: 309 time(s) in 270 post(s)
Try adding this at the start of the script:
Code:
sp.SendAltUp();
thanks 1 user thanked Rob for this useful post.
Kief on 9/13/2021(UTC)
Kief  
#16 Posted : Monday, September 13, 2021 7:11:23 PM(UTC)
Kief

Rank: Member

Reputation:

Groups: Approved
Joined: 9/5/2021(UTC)
Posts: 13
United Kingdom

Thanks: 7 times
Yes. That did it!

Thanks!
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.