!752 p { // Send information to whoever is listening on port 4989 S bashCmd = "echo -e 'windows key pressed\\n' | telnet localhost 4989"; File scriptFile = getProgramFile("converse.sh"); saveTextFile(scriptFile, bashCmd); S cmdToRun = "/bin/bash " + scriptFile.getPath(); assignWindowsKeyTo(bashQuote(cmdToRun)); } svoid assignWindowsKeyTo(S cmdToRun) ctex { if (!isLinux()) fail("This function is only implemented for Linux"); // Install xbindkeys if not there if (!new File("/usr/bin/xbindkeys").isFile()) { fail("xbindkeys not installed"); /* //print("xbindkeys not found, installing."); String sudoPassword = TinyBrainUtils.showPasswordDialog(new MiniDB(), null, "Please enter sudo password (for apt-get install xbindkeys)", ""); if (sudoPassword == null) return; // No password, interrupt Logger oldLogger = Log.getLogger(); Log.setLoggerForThread(new NonLogger()); // don't log sudo password try { backtick("echo " + sudoPassword + " | sudo -S apt-get -y install xbindkeys"); } finally { Log.setLoggerForThread(oldLogger); } */ } else { print("Good: xbindkeys is installed."); } if (!new File("/usr/bin/xbindkeys").isFile()) throw new RuntimeException("Could not install xbindkeys"); print("xbindkeys there."); print("Creating ~/.xbindkeysrc"); S homedir = userHome(); print("home dir: " + homedir); // We just overwrite .xbindkeysrc... hopefully no other keys were bound by user :) File dot_xbindkeysrc = new File(homedir, ".xbindkeysrc"); print("writing: " + dot_xbindkeysrc); saveTextFile(dot_xbindkeysrc, "# This file was created by " + getProgramURL() + "\n" + "\n" + cmdToRun + "\n" + " c:133\n" // It's the Windows key! ); print("Adding xbindkeys to your autostart"); // make xbindkeys.desktop (autostart xbindkeys for local user) File autostart_dir = new File(homedir, ".config/autostart"); print("Creating " + autostart_dir); autostart_dir.mkdirs(); File autostart_xbindkeys = new File(autostart_dir, "xbindkeys.desktop"); print("Writing " + autostart_xbindkeys); saveTextFile(autostart_xbindkeys, " [Desktop Entry]\n" + " Version=1.0\n" + " Name=xbindkeys\n" + " Name[en_US]=xbindkeys\n" + " Comment=Binds hotkeys to actions\n" + " Exec=xbindkeys\n" + " Icon=\n" + " Terminal=false\n" + " Type=Application\n" + " Encoding=UTF-8\n" + " Categories=Accessories\n"); print("Starting xbindkeys"); S processes = backtick("ps --no-heading -C xbindkeys"); if (!processes.isEmpty()) { print(" xbindkeys already running - restarting."); backtick("killall xbindkeys && xbindkeys"); } else { backtick("xbindkeys"); print(" xbindkeys started."); } print("All done, Windows key assigned."); }