Skip to content

Instantly share code, notes, and snippets.

@rubyu
Last active March 3, 2019 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubyu/3f6ea0925f0efcefca41272c20507c1b to your computer and use it in GitHub Desktop.
Save rubyu/3f6ea0925f0efcefca41272c20507c1b to your computer and use it in GitHub Desktop.
普通のキーボードにファンクションキーを導入するサンプル
// Example for introducing function key to normal keyboard.
// Profile for keyboard geatures.
DeclareProfile("Keyboard");
{
var fn = false;
var Whenever = When(ctx =>
{
return true;
});
Whenever.
OnDecomposed(Keys.RShiftKey).
Press(ctx => fn = true).
Release(ctx => fn = false);
void swapIfFn(
Crevice.Core.DSL.WhenElement<Crevice.GestureMachine.EvaluationContext, Crevice.GestureMachine.ExecutionContext> when,
Crevice.UserScript.Keys.LogicalSystemKey from,
Crevice.UserScript.Keys.LogicalSystemKey to
) {
when.
OnDecomposed(from).
Press(ctx => {
if (fn) {
SendInput.KeyDown(to);
return;
}
SendInput.KeyDown(from);
}).
Release(ctx => {
if (fn) {
SendInput.KeyUp(to);
return;
}
SendInput.KeyUp(from);
});
}
void disableIfFn(
Crevice.Core.DSL.WhenElement<Crevice.GestureMachine.EvaluationContext, Crevice.GestureMachine.ExecutionContext> when,
Crevice.UserScript.Keys.LogicalSystemKey from
) {
when.
OnDecomposed(from).
Press(ctx => {
if (fn) {
return;
}
SendInput.KeyDown(from);
}).
Release(ctx => {
if (fn) {
return;
}
SendInput.KeyUp(from);
});
}
// fn + 1234567890-^ -> F1-12
swapIfFn(Whenever, Keys.D1, Keys.F1);
swapIfFn(Whenever, Keys.D2, Keys.F2);
swapIfFn(Whenever, Keys.D3, Keys.F3);
swapIfFn(Whenever, Keys.D4, Keys.F4);
swapIfFn(Whenever, Keys.D5, Keys.F5);
swapIfFn(Whenever, Keys.D6, Keys.F6);
swapIfFn(Whenever, Keys.D7, Keys.F7);
swapIfFn(Whenever, Keys.D8, Keys.F8);
swapIfFn(Whenever, Keys.D9, Keys.F9);
swapIfFn(Whenever, Keys.D0, Keys.F10);
swapIfFn(Whenever, Keys.OemMinus, Keys.F11);
swapIfFn(Whenever, Keys.Oem7, Keys.F12);
// fn + JIKL -> ←↑↓→
swapIfFn(Whenever, Keys.J, Keys.Left);
swapIfFn(Whenever, Keys.I, Keys.Up);
swapIfFn(Whenever, Keys.K, Keys.Down);
swapIfFn(Whenever, Keys.L, Keys.Right);
// fn + UOP; -> N/A
disableIfFn(Whenever, Keys.U);
disableIfFn(Whenever, Keys.O);
disableIfFn(Whenever, Keys.P);
disableIfFn(Whenever, Keys.Oemplus);
// fn + @ -> Home
swapIfFn(Whenever, Keys.Oem3, Keys.Home);
// fn + : -> End
swapIfFn(Whenever, Keys.Oem1, Keys.End);
// fn + [ -> PageUp
swapIfFn(Whenever, Keys.Oem4, Keys.PageUp);
// fn + ] -> PageDown
swapIfFn(Whenever, Keys.Oem6, Keys.PageDown);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment