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).

1  
!752
2  
3  
p {
4  
  // Send information to whoever is listening on port 4989
5  
  S bashCmd = "echo -e 'windows key pressed\\n' | telnet localhost 4989";
6  
7  
  File scriptFile = getProgramFile("converse.sh");
8  
  saveTextFile(scriptFile, bashCmd);
9  
  S cmdToRun = "/bin/bash " + scriptFile.getPath();
10  
11  
  assignWindowsKeyTo(bashQuote(cmdToRun));
12  
}
13  
14  
svoid assignWindowsKeyTo(S cmdToRun) ctex {
15  
  if (!isLinux())
16  
    fail("This function is only implemented for Linux");
17  
18  
  // Install xbindkeys if not there
19  
20  
  if (!new File("/usr/bin/xbindkeys").isFile()) {
21  
    fail("xbindkeys not installed");
22  
23  
    /*
24  
    //print("xbindkeys not found, installing.");
25  
    String sudoPassword = TinyBrainUtils.showPasswordDialog(new MiniDB(), null,
26  
      "Please enter sudo password (for apt-get install xbindkeys)", "");
27  
    if (sudoPassword == null)
28  
      return; // No password, interrupt
29  
30  
    Logger oldLogger = Log.getLogger();
31  
    Log.setLoggerForThread(new NonLogger()); // don't log sudo password
32  
    try {
33  
      backtick("echo " + sudoPassword + " | sudo -S apt-get -y install xbindkeys");
34  
    } finally {
35  
      Log.setLoggerForThread(oldLogger);
36  
    }
37  
    */
38  
  } else {
39  
    print("Good: xbindkeys is installed.");
40  
  }
41  
42  
  if (!new File("/usr/bin/xbindkeys").isFile())
43  
    throw new RuntimeException("Could not install xbindkeys");
44  
  print("xbindkeys there.");
45  
46  
  print("Creating ~/.xbindkeysrc");
47  
48  
  S homedir = userHome();
49  
  print("home dir: " + homedir);
50  
51  
  // We just overwrite .xbindkeysrc... hopefully no other keys were bound by user :)
52  
53  
  File dot_xbindkeysrc = new File(homedir, ".xbindkeysrc");
54  
  print("writing: " + dot_xbindkeysrc);
55  
  saveTextFile(dot_xbindkeysrc,
56  
    "# This file was created by " + getProgramURL() + "\n" +
57  
      "\n" +
58  
      cmdToRun + "\n" +
59  
      "    c:133\n" // It's the Windows key!
60  
  );
61  
62  
  print("Adding xbindkeys to your autostart");
63  
64  
  // make xbindkeys.desktop (autostart xbindkeys for local user)
65  
66  
  File autostart_dir = new File(homedir, ".config/autostart");
67  
  print("Creating " + autostart_dir);
68  
  autostart_dir.mkdirs();
69  
  File autostart_xbindkeys = new File(autostart_dir, "xbindkeys.desktop");
70  
  print("Writing " + autostart_xbindkeys);
71  
  saveTextFile(autostart_xbindkeys,
72  
    "    [Desktop Entry]\n" +
73  
    "    Version=1.0\n" +
74  
    "    Name=xbindkeys\n" +
75  
    "    Name[en_US]=xbindkeys\n" +
76  
    "    Comment=Binds hotkeys to actions\n" +
77  
    "      Exec=xbindkeys\n" +
78  
    "    Icon=\n" +
79  
    "      Terminal=false\n" +
80  
    "    Type=Application\n" +
81  
    "    Encoding=UTF-8\n" +
82  
    "    Categories=Accessories\n");
83  
84  
  print("Starting xbindkeys");
85  
86  
  S processes = backtick("ps --no-heading -C xbindkeys");
87  
88  
  if (!processes.isEmpty()) {
89  
    print("  xbindkeys already running - restarting.");
90  
    backtick("killall xbindkeys && xbindkeys");
91  
  } else {
92  
    backtick("xbindkeys");
93  
    print("  xbindkeys started.");
94  
  }
95  
96  
  print("All done, Windows key assigned.");
97  
}

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: 554 / 535
Referenced in: [show references]