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

Notification

Icon
Error

Options
Go to last post Go to first unread
randomConstant  
#1 Posted : Tuesday, November 23, 2021 2:13:56 PM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 135

Thanks: 35 times
Was thanked: 18 time(s) in 15 post(s)
Hi all,

Following are some of the ways to send keystrokes in S+:

SendKeys:
Code:
sp.SendKeys("^c");


SendVKey:
Code:
sp.SendVKey(vk.CONTROL);


and SendModifiedVKeys:
Code:
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]);


sp.SendKeys is used in the sample scripts of S+ such as the copy and cut scripts, but I started using sp.SendModifiedVKeys due to its ability to timely send complex keystrokes.

I've always been curious if converting all sp.SendKeys in my scripts to sp.SendModifiedVKeys for the sake of consistency would have any affect on the resources, performance, and efficiency of script. I haven't seen a related discussion on forum yet and would love to know the pros and cons of these three methods regarding S+ performance.

Thanks
thanks 1 user thanked randomConstant for this useful post.
Nhan000 on 5/11/2023(UTC)
Rob  
#2 Posted : Tuesday, November 23, 2021 3:52:40 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)
SendVKey/SendModifiedVKeys/(any of the VKey ones) are the preferred method for a few reasons, mostly international compatibility.

I'm not 100% sure on performance as I haven't benchmarked it, but I would assume it is better because it's not parsing/converting a string to keystrokes.
The values passed into the VKey methods are directly resolved to keycodes.
thanks 2 users thanked Rob for this useful post.
randomConstant on 11/23/2021(UTC), Nhan000 on 5/11/2023(UTC)
randomConstant  
#3 Posted : Tuesday, November 23, 2021 5:12:27 PM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 135

Thanks: 35 times
Was thanked: 18 time(s) in 15 post(s)
Alright thank you very much Rob.
Aguilucho  
#4 Posted : Tuesday, March 28, 2023 1:01:29 AM(UTC)
Aguilucho

Rank: Newbie

Reputation:

Groups: Approved
Joined: 10/11/2020(UTC)
Posts: 1
Chile
Location: Santiago

Hi Rob
I've used s+ for years BigGrin , although I know very little about scripting.
Knowing S+.net, I'm a bit lost...
Basic Question: How do I use sp.SendVKey or sp.SendModifiedVKeys to repeat a press key?
For example, sp.SendVKey(vk.RMENU) for 3 times?

Global Question: To use a command, I have to surf the entire site
and then search for many other places
After spending several days I have not found an answer to the basic question...
Now, Where can I find a manual with the codes used by S+?
Sometimes I find something in java forums, sometimes in javascript forums, or in c# etc.
What kind of sites should I look at first?
I don't know if this will be a good thread for the question,
which can be referred to another one less specific and then
it can serve more users...
My thanks and blessings, Rob
Rob  
#5 Posted : Friday, March 31, 2023 3:37:56 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)
It's challenging because S+ exposes so much of the .NET Framework that it's just not practical to reproduce all of Microsoft's documentation. But I do understand it can be challenging to know where to start.

In regards to the script engine within S+, the language is JavaScript - which is connected to the .NET Framework via Microsoft ClearScript. So there is a mix of JavaScript syntax and .NET Framework objects/classes.

In general, I would say start with seeing if S+ has a built-in function (sp.) for what you want to do, as it will generally handle most common things.
If there isn't something built-in, then look for C# examples and it will usually get you pretty close, with some minor tweak.

If you join the Discord server (link on Downloads page), I can usually whip up a quick example script for you pretty quickly.

To send a key multiple times, you can just duplicate the line:
Code:
sp.SendVKey(vk.RMENU);
sp.SendVKey(vk.RMENU);
sp.SendVKey(vk.RMENU);

Or setup a loop:
Code:
for(var i = 0; i < 3; i++) {
    sp.SendVKey(vk.RMENU);
}
Users browsing this topic
Guest
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.