Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
When you hold a key down, the DOWN event is sent repeatedly, like when you type the letter Y and hold it down, you get: YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY So you have to account for repeated key down messages, it was continually clearing the suppress hot key bool. This seems to work for me: Code:if(__spEngineWrapper.Engine.Name == sp.EngineList().Last().Engine.Name) {
//This toggles on and off a synchronous mouse button hook event subscription
//If event already bound, disconnect
var mouseButtonEventObj = sp.GetStoredObject("mouseButtonEvent");
if(mouseButtonEventObj.GetType().FullName.includes('EventConnection')) {
mouseButtonEventObj.disconnect();
sp.DeleteStoredObject("mouseButtonEvent");
} else {
//Otherwise, create the event binding
//bind to synchronous event
var mouseButtonEvent = MouseHook.OnMouseHookButtonEventAsync.connect(
function (sender, mouseHookEvent) {
//Wrap all code in try/catch, exceptions will crash S+, such as calling clip.SetText with a null value
try {
if(mouseHookEvent.Button == MouseButtons.Left && mouseHookEvent.ButtonState == ButtonState.Down && (sp.GetKeyState(vk.LSHIFT) & 0x8000 || sp.GetKeyState(vk.RSHIFT) & 0x8000 || sp.GetKeyState(vk.SHIFT) & 0x8000))
{
//Do something when the left mouse button is released, but don't consume
sp.ShowBalloonTip('Title','Message here','Info',5000);
sp.StoreBool("SuppressHotkey", true);
}
}
catch{}
});
//Note that on S+ reload, events in Stored Object list have disconnect called on them
sp.StoreObject("mouseButtonEvent", mouseButtonEvent);
}
var keyboardEventObj = sp.GetStoredObject("keyboardEvent");
if(!keyboardEventObj.GetType().FullName.includes('EventConnection')) {
//Bind to the synchronous event
var keyboardEvent = KeyboardHook.OnKeyboardHookEventAsync.connect(
function (sender, keyboardHookEvent) {
//Wrap all code in try/catch, exceptions will crash S+, such as calling clip.SetText with a null value
try {
if(keyboardHookEvent.Key == vk.LSHIFT) {
if(keyboardHookEvent.KeyState == KeyState.Up) {
sp.StoreBool("ShiftDown", false);
if(!sp.GetStoredBool("SuppressHotkey")) {
// Shift only, no other keypresses since shift down
sp.SendWinDown();
sp.SendVKey(vk.SPACE);
sp.SendWinUp();
}
//removed consume, no reason to leave shift in the down state
} else {
if(!sp.GetStoredBool("ShiftDown")) {
// Shift down, reset variable
sp.StoreBool("SuppressHotkey", false);
}
sp.StoreBool("ShiftDown", true);
}
} else {
// If any other key pressed down while Shift is pressed, set var to ignore hotkey
if(keyboardHookEvent.KeyState == KeyState.Down && sp.GetKeyState(vk.LSHIFT) & 0x8000) {
sp.StoreBool("SuppressHotkey", true);
}
}
}
catch {}
});
sp.StoreObject("keyboardEvent", keyboardEvent);
}
}
|
1 user thanked Rob for this useful post.
|
|