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

Notification

Icon
Error

Options
Go to last post Go to first unread
2014218866  
#1 Posted : Wednesday, November 25, 2020 1:08:57 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 111
China

Thanks: 19 times
Was thanked: 1 time(s) in 1 post(s)
Dear Rob,
I'm glad to talk to you again, and I look forward to a new feature.
Is it possible to add double-click a modifier key to execute a script in the hotkey options? For example, double-click ‘Ctrl’ to execute a certain program, or press “Alt” twice to execute the Ctrl+C function, and look forward to your reply.
UserPostedImage
Rob  
#2 Posted : Wednesday, November 25, 2020 1:54:03 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 28 times
Was thanked: 419 time(s) in 356 post(s)
You might to see this thread:

https://forum.strokesplu...hotkey---a-good-approach

The current hot key functionality does not count keypresses and that would complicate other aspects to the overall hot key logic - so at this time it's not something that would be added to the core hot key functionality in S+.

Using the information in the thread above would be able to achieve this (make sure to enable keyboard hook even subscription in Options > Advanced), or perhaps someone will make a plug-in :)
thanks 1 user thanked Rob for this useful post.
2014218866 on 11/25/2020(UTC)
petercncn  
#3 Posted : Tuesday, December 1, 2020 3:27:05 PM(UTC)
petercncn

Rank: Member

Reputation:

Groups: Approved
Joined: 11/4/2020(UTC)
Posts: 12
China

Originally Posted by: Rob Go to Quoted Post
You might to see this thread:

https://forum.strokesplu...hotkey---a-good-approach

The current hot key functionality does not count keypresses and that would complicate other aspects to the overall hot key logic - so at this time it's not something that would be added to the core hot key functionality in S+.

Using the information in the thread above would be able to achieve this (make sure to enable keyboard hook even subscription in Options > Advanced), or perhaps someone will make a plug-in :)


Thank you, Rob.
And after I research the code in the threat you gave, I modified a good script which you can use for sample to give more keys more usage:


//===== 多次按左Ctrl执行不同命令,开始
// 参考:https://forum.strokesplus.net/posts/t8266findunread-Double-CTRL-press-as-hotkey---a-good-approach,
//参考: https://forum.strokesplu...oard-Event-Subscriptions
// This subscribes for an asynchronous keyboard hook event
// Dont forget to enable Keyboard Hook Event Subscription in Options!
var keyboardHookEventLctrl = sp.GetStoredObject("keyboardEvent");
var keyPressTimeoutLctrl = 1000; // 1 second
sp.StoreNumber("LctrlKeyPressCounter", 0);

if (!keyboardHookEventLctrl.GetType().FullName.includes('EventConnection')) {
var keyboardEventLctrl = KeyboardHook.OnKeyboardHookEventAsync.connect(
function (sender, keyboardHookEvent) {
try {
if (keyboardHookEvent.Key == vk.LCONTROL && keyboardHookEvent.KeyState == KeyState.Up) {
sp.StoreNumber("LctrlKeyPressCounter", sp.GetStoredNumber("LctrlKeyPressCounter") + 1);
if (sp.GetStoredNumber("LctrlKeyPressCounter") == 1) {
// Start Timer
sp.CreateTimer('LctrlKeyTimeout', keyPressTimeoutLctrl, -1, String.raw`
// React on number of key presses:
switch (sp.GetStoredNumber("LctrlKeyPressCounter")) {
case 1:
// Don´t do anything to keep original function and not interfere with several
// hotkey combinations (ctrl-c, ctrl-s, ...)
break;
case 2:
// Don´t do anything to keep original function and not interfere with several
break;
case 3:
// Do some amazing stuff, 连续按3次左ctrl,执行以下自定义的命令。由于两次ctrl是Listary的热
//键,Listary会获得焦点,所以多次左ctrl执行的命令应为不需要特定焦点的全局命令或宏。
// eval(sp.GetMacroScript("Functions", "MouseRestrict1D"));
sp.SendModifiedVKeys([vk.LWIN], [vk.VK_E]); //连续按3次左ctrl 为打开我的电脑

break;

case 4:
// Do some amazing stuff,暂时空置
sp.SendVKey(vk.VOLUME_MUTE); //连续按4次左ctrl 为切换静音

break;

default:
// sp.MessageBox("# pressed L-Ctrl: " + sp.GetStoredNumber("LctrlKeyPressCounter"), "Message from S+");
var currpt = sp.GetCurrentMousePoint();var info = new DisplayTextInfo();
info.Title = "一共" + sp.GetStoredNumber("LctrlKeyPressCounter") + "次";
info.Message = "已连续按左Ctrl键" ;
info.Location = (currpt.X-100)+','+(currpt.Y-150);
info.Duration = 2000;info.TitleAlignment = "Center";info.Opacity = 0.7;info.MessageAlignment = "Left";info.TitleFont = new Font("Segoe UI", 33, host.flags(FontStyle.Bold));info.MessageFont = new Font("Segoe UI Semibold", 17);info.BackColor = "black";info.ForeColor = "white";info.Padding = 5;
sp.DisplayText(info);

break;
}
sp.StoreNumber("LctrlKeyPressCounter", 0);
sp.DeleteTimer('LctrlKeyTimeout');
`);
}
}
}
catch(err) {
sp.MessageBox("An error occured while processing L-CTRL hotkey:\n\n" + err.message, "Message from S+");

}
}
);
sp.StoreObject("keyboardEvent", keyboardEventLctrl);
}
//=====多次按左Ctrl执行不同命令,结束

//===== 多次按右Ctrl执行不同命令,开始
// 参考:https://forum.strokesplus.net/posts/t8266findunread-Double-CTRL-press-as-hotkey---a-good-approach,
//参考: https://forum.strokesplu...oard-Event-Subscriptions

// This subscribes for an asynchronous keyboard hook event
// Dont forget to enable Keyboard Hook Event Subscription in Options!
var keyboardHookEventRctrl = sp.GetStoredObject("keyboardEventRctrl");
var keyPressTimeoutRctrl = 1000; // 1 second
sp.StoreNumber("RctrlKeyPressCounter", 0);

if (!keyboardHookEventRctrl.GetType().FullName.includes('EventConnection')) {
var keyboardEventRctrl = KeyboardHook.OnKeyboardHookEventAsync.connect(
function (sender, keyboardHookEventRctrl) {
try {
if (keyboardHookEventRctrl.Key == vk.RCONTROL && keyboardHookEventRctrl.KeyState == KeyState.Up) {
sp.StoreNumber("RctrlKeyPressCounter", sp.GetStoredNumber("RctrlKeyPressCounter") + 1);
if (sp.GetStoredNumber("RctrlKeyPressCounter") == 1) {
// Start Timer
sp.CreateTimer('RctrlKeyTimeout', keyPressTimeoutRctrl, -1, String.raw`
// React on number of key presses:
switch (sp.GetStoredNumber("RctrlKeyPressCounter")) {
case 1:
// Don´t do anything to keep original function and not interfere with several
// hotkey combinations (ctrl-c, ctrl-s, ...)
break;
case 2:
// Don´t do anything to keep original function and not interfere with several
break;
case 3:
// Do some amazing stuff, 连续按3次右ctrl,执行以下自定义的命令。由于两次ctrl是Listary的热
//键,Listary会获得焦点,所以多次右ctrl执行的命令应为不需要特定焦点的全局命令或宏。
// eval(sp.GetMacroScript("Functions", "MouseRestrict1D"));
sp.SendModifiedVKeys([vk.LWIN], [vk.VK_E]); //连续按3次右ctrl 为打开我的电脑

break;

case 4:
// Do some amazing stuff,暂时空置
sp.SendVKey(vk.VOLUME_MUTE); //连续按4次右ctrl 为切换静音

break;

default:
// sp.MessageBox("# pressed R-Ctrl: " + sp.GetStoredNumber("RctrlKeyPressCounter"), "Message from S+");
var currpt = sp.GetCurrentMousePoint();var info = new DisplayTextInfo();
info.Title = "一共" + sp.GetStoredNumber("RctrlKeyPressCounter") + "次";
info.Message = "已连续按右Ctrl键" ;
info.Location = (currpt.X-100)+','+(currpt.Y-150);
info.Duration = 2000;info.TitleAlignment = "Center";info.Opacity = 0.7;info.MessageAlignment = "Left";info.TitleFont = new Font("Segoe UI", 33, host.flags(FontStyle.Bold));info.MessageFont = new Font("Segoe UI Semibold", 17);info.BackColor = "black";info.ForeColor = "white";info.Padding = 5;
sp.DisplayText(info);
break;
}
sp.StoreNumber("RctrlKeyPressCounter", 0);
sp.DeleteTimer('RctrlKeyTimeout');
`);
}
}
}
catch(err) {
sp.MessageBox("An error occured while processing R-CTRL hotkey:\n\n" + err.message, "Message from S+");

}
}
);
sp.StoreObject("keyboardEventRctrl", keyboardEventRctrl);
}
//=====多次按右Ctrl执行不同命令,结束
//=====可以开发可多次按下执行不同命令的按键有:Alt, Tab键上方的`键,F1~F12,只需要用上面的代码模板搜索替换Rctrl与vk.RCONTROL即可。
// You can give Alt, `,F1~F12 difinations by using the above sample code with search and repleace "Rctrl" and vk.RCONTROL






2014218866  
#4 Posted : Wednesday, December 2, 2020 12:07:40 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 111
China

Thanks: 19 times
Was thanked: 1 time(s) in 1 post(s)
Dear petercncn,

When using this script, you will find that it is not perfect.
For example, when you repeatedly paste some text, it will open My Computer.
So I still prefer to perform this function in hotkeys rather than using modifier keys.

Thank you for your participation
petercncn  
#5 Posted : Friday, December 4, 2020 4:03:45 PM(UTC)
petercncn

Rank: Member

Reputation:

Groups: Approved
Joined: 11/4/2020(UTC)
Posts: 12
China

Originally Posted by: 2014218866 Go to Quoted Post
Dear petercncn,

When using this script, you will find that it is not perfect.
For example, when you repeatedly paste some text, it will open My Computer.
So I still prefer to perform this function in hotkeys rather than using modifier keys.

Thank you for your participation



I also find this problem. So I delete the code about the left Ctrl and let the Left Ctrl get the origal function.
Thank you.

Edited by user Friday, December 4, 2020 4:09:13 PM(UTC)  | Reason: Not specified

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.