Posted 05 April 2012 - 01:14 PM
Playing online?
Can't get Ctrl+V to work correctly for ComputerCraft?
Fighting the urge to scoop your eyes out with a rusty spoon white trying to program in ComputerCraft directly?
Did you know you can get linux to type the contents of the clipboard into minecraft?… Here's how:
First, install some tools:
You'll need to install "xdotool" and "xbindkeys."
You can install these from the command line with "[sudo] apt-get install xdotool, xbindkeys"
Then, copy and paste this script
.. into a sensible location (for example, to "~/autopaste.py)
You'll need to make that script 'runnable', which assuming you've saved it as something like "~/autopaste.py" can be done (via command line) with "chmod +x autopaste.py"
Grab "Pyperclip" for clipboard access
The excellent "pyperclip" module is required, so you'll need to follow that link, and save "pyperclip.py" in the same location.
Set up configuration file for xbindkeys
Then, get xbindkeys to create a default config file and place it where it'll get automatically loaded using:
"xbindkeys –defaults > $HOME/.xbindkeysrc"
Open up this file, and comment out those examples if you don't want them. We're going to add a command to this config file to run the script you copied when you press "Windows+V". Copy the command below into the file:
Last, watch it run:
Make sure xbindkeys is running (you can also check the current shortcut keys with "xbindkeys -s"), then open up an editor in ComputerCraft (within minecraft), copy some code to the clipboard (just as you would normally), and hit "Windows+V"… you should now see linux doing the frantic typing for you, leaving you to make coffee.
More info + Other notes:
If you want to change the key combination, run "xbindkeys -mk", press the key combination you want, and replace "Mod4+Super_L+v" in the config file with the results that xbindkeys prints out for you.
Changing the typing speed
At the top of "~/autoclip.py" (assuming that is what you saved the script above as), there is a variable "key_press_delay_ms" which is the delay (in milliseconds) between each key press. If you find the typing speed too fast (for example, if latency is causing characters to skip), increase the delay.
It's missing characters as it's typing!
You may have too much lag on your connection for how fast the clipboard is being typed. See "Changing the typing speed" for help with that.
Can't get Ctrl+V to work correctly for ComputerCraft?
Fighting the urge to scoop your eyes out with a rusty spoon white trying to program in ComputerCraft directly?
Did you know you can get linux to type the contents of the clipboard into minecraft?… Here's how:
First, install some tools:
You'll need to install "xdotool" and "xbindkeys."
You can install these from the command line with "[sudo] apt-get install xdotool, xbindkeys"
Then, copy and paste this script
.. into a sensible location (for example, to "~/autopaste.py)
Spoiler
#!/usr/bin/python
import subprocess, time
key_press_delay_ms = 12
character_mapping = [
{ "char":'\n', "mapped": 'Return' },
{ "char":'-', "mapped": 'minus'},
{ "char":'[', "mapped": 'bracketleft'},
{ "char":']', "mapped": 'bracketright'},
{ "char":'{', "mapped": 'braceleft'},
{ "char":'}', "mapped": 'braceright'},
{ "char":'\"', "mapped": 'quotedbl'},
{ "char":'&', "mapped": 'ampersand'},
{ "char":'/', "mapped": 'slash'},
{ "char":'\`', "mapped": 'grave'},
{ "char":'$', "mapped": 'dollar'},
{ "char":'\'', "mapped": 'apostrophe'},
]
def flushTyping( arguements ):
#print("Typing:\n" + arguements )
time.sleep( key_press_delay_ms * 1.0 / 1000 )
command = ["xdotool", "type", "--clearmodifiers", "--delay", str( key_press_delay_ms ), str( arguements )]
subprocess.call(command)
def flushKeypress( arguements ):
#print("Keypress:\n" + arguements)
time.sleep( key_press_delay_ms * 1.0 / 1000 )
arguements = arguements.strip().split(" ")
#print ["xdotool", "type", "--clearmodifiers", "--delay", key_press_delay_ms ] + arguements
command = ["xdotool", "key", "--clearmodifiers", "--delay", str( key_press_delay_ms )] + arguements
subprocess.call( command )
if __name__ == "__main__":
import pyperclip
contents = pyperclip.getcb()
keypress_arguements = ""
typing_arguements = ""
last_addition = "typing"
character_checklist = []
for item in character_mapping:
character_checklist.append( item["char"] )
for character in contents:
if character in character_checklist:
for item in character_mapping:
if item["char"] == character:
keypress_arguements += " " + item["mapped"]
break
if last_addition == 'typing':
flushTyping( typing_arguements )
typing_arguements = ""
last_addition = 'keypress'
else:
typing_arguements += character
if last_addition == 'keypress':
flushKeypress( keypress_arguements )
keypress_arguements = ""
last_addition = 'typing'
if last_addition == "typing":
flushTyping( typing_arguements )
else:
flushKeypress( keypress_arguements )
You'll need to make that script 'runnable', which assuming you've saved it as something like "~/autopaste.py" can be done (via command line) with "chmod +x autopaste.py"
Grab "Pyperclip" for clipboard access
The excellent "pyperclip" module is required, so you'll need to follow that link, and save "pyperclip.py" in the same location.
Set up configuration file for xbindkeys
Then, get xbindkeys to create a default config file and place it where it'll get automatically loaded using:
"xbindkeys –defaults > $HOME/.xbindkeysrc"
Open up this file, and comment out those examples if you don't want them. We're going to add a command to this config file to run the script you copied when you press "Windows+V". Copy the command below into the file:
"~/autoclip.py"
Mod4+Super_L+v
Last, watch it run:
Make sure xbindkeys is running (you can also check the current shortcut keys with "xbindkeys -s"), then open up an editor in ComputerCraft (within minecraft), copy some code to the clipboard (just as you would normally), and hit "Windows+V"… you should now see linux doing the frantic typing for you, leaving you to make coffee.
More info + Other notes:
Spoiler
Changing the shortcut keyIf you want to change the key combination, run "xbindkeys -mk", press the key combination you want, and replace "Mod4+Super_L+v" in the config file with the results that xbindkeys prints out for you.
Changing the typing speed
At the top of "~/autoclip.py" (assuming that is what you saved the script above as), there is a variable "key_press_delay_ms" which is the delay (in milliseconds) between each key press. If you find the typing speed too fast (for example, if latency is causing characters to skip), increase the delay.
It's missing characters as it's typing!
You may have too much lag on your connection for how fast the clipboard is being typed. See "Changing the typing speed" for help with that.