1
$\begingroup$

What is the most portable way to assign keyboard shortcuts unique to each notebook?

To clarify I would like to have the keyboard shortcut change when simply changing the current InputNotebook.

Currently I'm have the following code which allows for me to essentially have the defined function be defined in a notebook and execute in the Global` context.

FrontEndExecute@
 FrontEnd`AddMenuCommands[
  "DuplicatePreviousOutput", {MenuItem["Ctrl &q", 
    FrontEnd`KernelExecute@ToExpression@MakeBoxes[
       F2[]
       ], MenuKey["q", Modifiers -> {"Control"}], 
    System`MenuEvaluator -> Automatic]}]

I would like to somehow attach functions to notebooks without changing the context(most ideal). Alternatively I might be able to use something like a custom FrontEnd'NotebookExecute instead of FrontEnd'KernelExecute.

$\endgroup$
0
$\begingroup$

Taking advantage of Mike question here.

FrontEndExecute@
 FrontEnd`AddMenuCommands[
  "DuplicatePreviousOutput", {MenuItem["Ctrl &F2", 
    FrontEnd`KernelExecute@ToExpression@MakeBoxes[

       CurrentValue[
          InputNotebook[], {TaggingRules, "keyShortcuts", "F2"}][];

       ], MenuKey["F2", Modifiers -> {"Control"}], 
    System`MenuEvaluator -> Automatic]}]
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.