Rank: Member
Groups: Approved
Joined: 9/5/2021(UTC) Posts: 16  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.
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,315  Location: Tampa, FL Thanks: 28 times Was thanked: 412 time(s) in 352 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.
|
 1 user thanked Rob for this useful post.
|
|
|
Rank: Member
Groups: Approved
Joined: 9/5/2021(UTC) Posts: 16  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
|
|
|
|
Rank: Member
Groups: Approved
Joined: 9/5/2021(UTC) Posts: 16  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
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,315  Location: Tampa, FL Thanks: 28 times Was thanked: 412 time(s) in 352 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") ){
}
|
 1 user thanked Rob for this useful post.
|
|
|
Rank: Member
Groups: Approved
Joined: 9/5/2021(UTC) Posts: 16  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.
|
|
|
|
Rank: Member
Groups: Approved
Joined: 9/5/2021(UTC) Posts: 16  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: 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.  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
|
|
|
|
Rank: Member
Groups: Approved
Joined: 9/5/2021(UTC) Posts: 16  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 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
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,315  Location: Tampa, FL Thanks: 28 times Was thanked: 412 time(s) in 352 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.
|
 1 user thanked Rob for this useful post.
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,315  Location: Tampa, FL Thanks: 28 times Was thanked: 412 time(s) in 352 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.
|
 1 user thanked Rob for this useful post.
|
|
|
Rank: Member
Groups: Approved
Joined: 9/5/2021(UTC) Posts: 16  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
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,315  Location: Tampa, FL Thanks: 28 times Was thanked: 412 time(s) in 352 post(s)
|
Oh right, backslashes are escape characters... can't believe I didn't think about that!
|
 1 user thanked Rob for this useful post.
|
|
|
Rank: Member
Groups: Approved
Joined: 9/5/2021(UTC) Posts: 16  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
|
|
|
|
Rank: Member
Groups: Approved
Joined: 9/5/2021(UTC) Posts: 16  Thanks: 7 times
|
I am now experiencing another issue. I can't say if this is App specific (in this case Ableton)  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
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,315  Location: Tampa, FL Thanks: 28 times Was thanked: 412 time(s) in 352 post(s)
|
Try adding this at the start of the script:
|
 1 user thanked Rob for this useful post.
|
|
|
Rank: Member
Groups: Approved
Joined: 9/5/2021(UTC) Posts: 16  Thanks: 7 times
|
|
|
|
|
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.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close