Dear @andheum, I’d like to have a Button that can be triggered by a keyboard shortcut.
Is there a simple way I can adapt the script above or does that require a whole new script?
Thanks for your help!
Dear @andheum, I’d like to have a Button that can be triggered by a keyboard shortcut.
Is there a simple way I can adapt the script above or does that require a whole new script?
Thanks for your help!
private void RunScript(object button, bool active, double increment, ref object A)
{
_btn = (GH_ButtonObject) button;
Instances.DocumentEditor.KeyDown -= new KeyEventHandler(KeyDownEventHandler);
Instances.DocumentEditor.KeyUp -= new KeyEventHandler(KeyUpEventHandler);
if(active)
{
Instances.DocumentEditor.KeyDown += new KeyEventHandler(KeyDownEventHandler);
Instances.DocumentEditor.KeyUp += new KeyEventHandler(KeyUpEventHandler);
}
}
// <Custom additional code>
GH_ButtonObject _btn;
void KeyDownEventHandler(object sender, KeyEventArgs e)
{
if(e.KeyCode != Keys.F7 || _btn.ButtonDown) return;
_btn.ButtonDown = true;
_btn.ExpireSolution(true);
}
void KeyUpEventHandler(object sender, KeyEventArgs e)
{
if(e.KeyCode != Keys.F7 || !_btn.ButtonDown) return;
_btn.ButtonDown = false;
_btn.ExpireSolution(true);
}
// </Custom additional code>
F7.gh (9.4 KB)
Thank you so much! Exactly what I wanted!