From 182b3cdf6a5c71a2ab8d8d033ab9746bf7e368ae Mon Sep 17 00:00:00 2001
From: Albert Graef <aggraef@gmail.com>
Date: Sun, 30 Oct 2016 19:14:23 +0100
Subject: [PATCH] Preliminary fix for the "dsp on" (Ctrl+/) keybinding.

- Make the Ctrl+/ keybinding work on German keyboards. This actually adds a
  binding for the 7 key which has the / symbol on it as a shifted key on
  German keyboards. For some reason that key isn't properly mapped by nw.js,
  so we do it manually. We do this unconditionally, as there doesn't seem to
  be a portable way to check which keyboard is actually active.

- Add a secondary, more international-keyboard-friendly, Ctrl+, keybinding for
  the "dsp on" function. The comma works much better for this function on some
  European keyboards which have the / key on the first row of the keyboard, as
  it is next to the period on most European keyboards (the Latin ones at
  least). The intention here is to make it easy on a wider range of keyboards
  to quickly turn off dsp and then turn it on again using keyboard commands.
  The Ctrl+, keybinding should work well for that purpose with almost any
  Latin keyboard. But note that the Ctrl+/ keybinding remains to be available
  as well for backward compatibility.

NOTE: Right now these only work in canvas windows, we still need to add
something similar to the console windows to make it work there.
---
 pd/nw/pd_canvas.js | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js
index 67f95c2a1..17228a87d 100644
--- a/pd/nw/pd_canvas.js
+++ b/pd/nw/pd_canvas.js
@@ -396,6 +396,20 @@ var canvas_events = (function() {
                     case 16: hack = "Shift"; break;
                     case 17: hack = "Control"; break;
                     case 18: hack = "Alt"; break;
+
+                    // keycode 188 = comma -- in contrast to / this is
+                    // next to the period on most Latin keyboards, so
+                    // much more convenient to quickly switch dsp off
+                    // and then on again
+                    case 188:
+                    // keycode 55 = 7 key (shifted = '/' on German keyboards)
+                    case 55:
+                        if (cmd_or_ctrl_key(evt)) {
+                            evt.preventDefault();
+                            pdgui.pdsend("pd dsp 1");
+                        }
+                        break;
+
                 }
                 if (hack !== null) {
                     pdgui.canvas_sendkey(name, 1, evt, hack, keydown_autorepeat);
-- 
GitLab