Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

97
LINES

< > BotCompany Repo | #1003536 // Assign Windows Key (on Linux)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1284L/9K/29K).

!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.");
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1003536
Snippet name: Assign Windows Key (on Linux)
Eternal ID of this version: #1003536/1
Text MD5: 89bc579b425b667c769e5a9f726b483a
Transpilation MD5: bd1f140747e6c101571ea5a8907e552a
Author: stefan
Category: javax / talking robots
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-17 17:16:02
Source code size: 2984 bytes / 97 lines
Pitched / IR pitched: No / No
Views / Downloads: 550 / 528
Referenced in: [show references]