This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
kazagistar's profile picture

Minecopy V2 [Linux][Windows]

Started by kazagistar, 03 June 2012 - 10:10 PM
kazagistar #1
Posted 04 June 2012 - 12:10 AM
Kazagistar's Computercraft Minecopy V2

Download Here

Ever get annoyed that you can't transfer your programs to a server that has HTTP disabled? Do you get annoyed when you have to type the same stuff into multiple computers? Want to code with a REAL text editor, and play SMP too? The solution is here!

Just open your minecraft and log in to a computercraft shell, then run the script with a list of files as parameters. Sit back and relax as it reads in the files, compresses them automagically, and rapidly types them into your minecraft window, saving them.

Notes: This program is buggy as hell. Make sure you call it from the same directory as the .lua files you want to transfer, because it will try to preserve relative file locations. If the text comes out with mistakes, slow down the keystrokes. If you want to be able to debug your code, disable compression. THE PROGRAM WILL RAPIDLY VOMIT KEYSTROKES INTO WHATEVER APPLICATION HAS FOCUS! IF YOU HAVE ANYTHING OTHER THEN MINECRAFT FOCUSED, IT WILL GET HAMMERED WITH LUA COMMANDS! YOU HAVE BEEN WARNED!

Enjoy, and please send me any questions you have, or patches you make to the code!


Linux requirements:
- Python 2.7
- libxdo
- lua [OPTIONAL: needed for lua file compression]

No links, this shit is trivial to install with a package manager on any distro. Once you have all the prerequesites, you should be able to just run the script.


Windows requirements:
- Python 2.7
http://www.python.org/download/
- pywin32 [OPTIONAL: needed for automatic window switching]
http://sourceforge.n.../pywin32/files/
- lua [OPTIONAL: needed for lua file compression]
http://code.google.c.../luaforwindows/

Windows is a little stupid when it comes to command line stuff like python. Go to My Computer>Properties>Advanced>Environment Variables, edit the PATH variable, and add to the end of it ";C:\Python27". Then you should be able to run the script doing something like: "> python scriptfolder/minecopy/minecopy.py luafolder/script1.lua luafolder/script2.lua"
kazagistar #2
Posted 04 June 2012 - 12:31 AM
Oh, and on I side note, here are some features I have been considering adding:

1) Configuration options outside of the script (to configure it currently, you have to edit the first couple lines of minecopy.py, bleh)
2) Support for Macs (so I can goof off at work in my lab)
3) Command line options and flags, for example, to disable lua compression on specific files, like data files.
Orwell #3
Posted 04 June 2012 - 12:59 PM
Nice and clean. : ) and handy for sure.

I was inspired by the concept, but I don't really like external dependencies on Windows (python, pywin32 :)/>/> ), so I quickly coded the same in c++ using only the windows api. It's Windows only (porting to Linux would practically mean rewriting the program ^^) and it doesn't support Lua compression. The code's much shorter though. : )
I don't think I'm posting it though, no need to interfere with your magnificent work. ;)/>/>

I also want to encourage you to expand it further, I don't plan on adding any more features to mine.
It would be especially handy to have some sort of 'config file'/package thingy that copies a set of files with directory structure, api's, startup files and everything to CC in one command. :D/>/>
kazagistar #4
Posted 04 June 2012 - 05:26 PM
Oh no, I realized during the project that python was the wrong choice of language, since most of what I was doing is making calls to the native API. Also I made it for linux originally, and yes "porting" it to windows required a full rewrite of most of it. I would be very interested in seeing your native version, and if you let me, might work off of it in the future, as I dislike dependancies as much as the next bloke, and lowering them might encourage more people to actually use it :)/>/>
Orwell #5
Posted 04 June 2012 - 10:19 PM
All right then, my program and source file are in the attachment. Anyone can change it however they like and distribute it in any way. On condition of course, that I'm credited under the name Orwell in source code (if distributed) and readme/description.

Kazagistar, you seem motivated to expand your and mine project further on, so I would definitely like you to work off of it in the future. :D/>/> c++ really is the wise choice here. :)/>/>

If you have any questions about my (uncommented) source code, PM me. Or better, ask your questions here so everyone can benefit from it. ;)/>/>

[EDIT]
Source code is also in this spoiler for quick access:
Spoiler
/* cc-typer.cpp
*   This program opens the Minecraft window (Minecraft should be
*   running with a Computercraft terminal open) and creates the files
*   passed by arguments on the CC computer.
*
*   author: Orwell
*   date: June 4 2012
*/
#define DEF_WINDOW_NAME "Minecraft"
#define DEF_STARTUP_TIME 1000
#define DEF_KEY_SPACING 5

#include <cstdlib>
#include <istream>
#include <fstream>
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
bool gotoMinecraft()
{
	HWND mc_hwnd = FindWindow(NULL, TEXT( DEF_WINDOW_NAME ));
	bool res = SetForegroundWindow(mc_hwnd);
	Sleep( DEF_STARTUP_TIME );
	return res;
}
void sendKeyDown(const BYTE vk)
{
	keybd_event(vk, 0x9e, 0, 0);
}
void sendKeyUp(const BYTE vk)
{
	keybd_event(vk, 0x9e, KEYEVENTF_KEYUP, 0);
}
void sendKey(const BYTE vk)
{
	sendKeyDown(vk);
	sendKeyUp(vk);
}
SHORT charToKeycode(const TCHAR c)
{
	return VkKeyScan(c);
}
/*
* Directly from: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646329(v=vs.85).aspx .
*/
class Key
{
public:
	Key(char c);
	virtual ~Key();
	BYTE getKeycode() { return keycode; }
	bool getAlt() { return alt; }
	bool getCtrl() { return ctrl; }
	bool getShift() { return shift; }
private:
	BYTE keycode;
	bool shift;
	bool ctrl;
	bool alt;
};
Key::Key(char c)
{
	SHORT code = charToKeycode(c);
	keycode = code &amp; 0x00ff;
	BYTE ms = (code &amp; 0xff00) >> 8;
	shift = ms &amp; 1;
	ctrl = ms &amp; 2;
	alt = ms &amp; 4;		
}
Key::~Key()
{
}

void sendChar(const char c)
{
	Key key(c);
	if(key.getCtrl() &amp;&amp; key.getKeycode() != VK_RETURN) {
		sendKeyDown(VK_CONTROL);
		if(key.getAlt()) {
			sendKeyUp(VK_CONTROL);
			Sleep( DEF_KEY_SPACING );
			sendKeyDown(VK_CONTROL);
			sendKeyDown(VK_MENU);
		}
	} else if(key.getAlt() &amp;&amp; key.getKeycode() != VK_RETURN) {
		sendKeyDown(VK_MENU);
	}
	if(key.getShift() &amp;&amp; key.getKeycode() != VK_RETURN) {
		sendKeyDown(VK_SHIFT);
	}
  
	sendKey(key.getKeycode());
  
	if(key.getCtrl() &amp;&amp; key.getKeycode() != VK_RETURN) {
		sendKeyUp(VK_CONTROL);
		if(key.getAlt()) {
			sendKeyUp(VK_MENU);
		}
	} else if (key.getAlt() &amp;&amp; key.getKeycode() != VK_RETURN) {
		sendKeyUp(VK_MENU);
	}
  
	if(key.getShift() &amp;&amp; key.getKeycode() != VK_RETURN) {
		sendKeyUp(VK_SHIFT);
	}
}
void sendString(const string s)
{
	for(unsigned int i=0; i < s.length(); i++) {
		sendChar(s[i]);
	}
}
void startEditingFile(const char* filename) {
	sendString("rm " + string(filename));
	sendKey(VK_RETURN);
	sendString("edit " + string(filename));
	sendKey(VK_RETURN);
}
void stopEditingFile() {
	sendKey(VK_CONTROL);
	sendKey(VK_RETURN);
	sendKey(VK_CONTROL);
	sendKey(VK_RIGHT);
	sendKey(VK_RETURN);
}
void enterContent(istream&amp; file)
{
	char* ptr_c = new char(1);
	while (!file.eof()) {
		file.read(ptr_c, 1);
		sendChar(*ptr_c);
		Sleep( DEF_KEY_SPACING );
	}
	delete ptr_c;
}
void writeFile(const char* filename) {
	ifstream file;
	file.open(filename);
	if(file.is_open()) {
		std::cout << "Writing file '" << filename << "'..." << std::endl;
		startEditingFile(filename);
		enterContent(file);
		stopEditingFile();
		file.close();
	} else {
		std::cerr << "Couldn't open file '" << filename << "'." << std::endl;
	}
}
void printUsage()
{
	std::cout << std::endl << "Made by Orwell." << std::endl << std::endl;
	std::cout << "This program opens the Minecraft window (Minecraft should be running with a" << std::endl
		<< "Computercraft terminal open) and creates the files that are passed by arguments" << std::endl
		<< "on the CC computer." << std::endl << std::endl;
	std::cout << "	usage: cc-type.exe file1 file2 ..." << std::endl;
}
int main(int argc, char *argv[])
{
	if(argc <= 1) {
		printUsage();
		return 0;
	}
	if(!gotoMinecraft()) {
		std::cerr << "Couldn't find the Minecraft window!" << std::endl;
		return 0;
	} else {
		std::cout << "Found Minecraft window." << std::endl;
	}
  
	for(unsigned int i=1; i<argc; i++) {
		writeFile(argv[i]);
	}
  
	std::cout << "Done writing files." << std::endl;
	return EXIT_SUCCESS;
}
Leo Verto #6
Posted 09 June 2012 - 01:32 PM
Just noticed you don't use window_name at all and just use 'Minecraft' as the window name.
So although I have set window_name to 'Tekkit', it would try to type into Minecraft.

I replaced shell.AppActivate('Minecraft') with shell.AppActivate(window_name) so it should work.
I hope Python uses variables like this…
kazagistar #7
Posted 10 June 2012 - 02:50 AM
Just noticed you don't use window_name at all and just use 'Minecraft' as the window name.
So although I have set window_name to 'Tekkit', it would try to type into Minecraft.

I replaced shell.AppActivate('Minecraft') with shell.AppActivate(window_name) so it should work.
I hope Python uses variables like this…
Heh good catch, sorry about that. Yeah, python is similar to lua in a lot of ways and they are both pretty easy to learn,python is just, um, better usually. But Lua is far far easier to embed, hence the choice of language.
Hexicube #8
Posted 10 June 2012 - 11:07 AM
I think I made something similar in java not too long ago, except it's purpose was to near silently hack a word game my friend made…fun times we have! :)/>/>
I would suggest actually using java to do it, as people using it are guaranteed to hava java…
kazagistar #9
Posted 10 June 2012 - 06:56 PM
Yeah, I totally missed the existence of java.awt.Robot somehow, thanks for pointing that out, better get cracking! Unfortunately, I can't figure out how to automatically switch window focus, and/or send commands to a specific window in java… delay method only.
ryan7136 #10
Posted 09 July 2012 - 08:06 AM
when i run, i get the following error:

ryanf@Fahy-ThinkCentre-A52:~/Downloads/minecopy$ python minecopy.py startup
Select minecraft window manually and make sure a computercraft terminal is open!
You have 10 seconds or bad things will happen!!!
Traceback (most recent call last):
File "minecopy.py", line 96, in <module>
copyfile(filename)
File "minecopy.py", line 83, in copyfile
typeout("rm "+filename+"nedit "+filename+"n")
File "minecopy.py", line 33, in typeout
xdo.xdo_type(xdo_context, 0, string, key_press_delay*1000000) # microseconds
ctypes.ArgumentError: argument 4: <type 'exceptions.TypeError'>: Don't know how to convert parameter 4
ryanf@Fahy-ThinkCentre-A52:~/Downloads/minecopy$



Any Help? Im on ubuntu


edit :
nvm, fixed by adding line

from ctypes import *
now CC forums, im not so clueless
Edited on 09 July 2012 - 10:31 PM
Tristan #11
Posted 11 July 2012 - 01:48 AM
I don't understand how to use this, tutorial?
Snowz #12
Posted 17 August 2012 - 08:54 AM
What if i use tekkit? It will work on minecraft, but not tekkit.
mad-murdock #13
Posted 18 August 2012 - 04:31 PM
tip: if possible, prefer ssh+vim or sftp
just saying…
FuzzyPurp #14
Posted 03 September 2012 - 09:46 PM
Moved to API's &amp; Utilities.
Cranium #15
Posted 17 September 2012 - 03:34 PM
Do either of these work for Tekkit? I'm on a Tekkit server with HTTP disabled. I would love to make sure either works before downloading.
etopsirhc #16
Posted 17 September 2012 - 10:37 PM
its set up to try and switch to any window named minecraft , but if it cant find any ( cause your using tekkit ) you can manualy focus that window cause theirs a 10 sec delay before it will start spewing text
tdlab #17
Posted 25 September 2012 - 12:13 PM
All right then, my program and source file are in the attachment. Anyone can change it however they like and distribute it in any way. On condition of course, that I'm credited under the name Orwell in source code (if distributed) and readme/description.

Kazagistar, you seem motivated to expand your and mine project further on, so I would definitely like you to work off of it in the future. ;)/>/> c++ really is the wise choice here. :P/>/>

If you have any questions about my (uncommented) source code, PM me. Or better, ask your questions here so everyone can benefit from it. :D/>/>

[EDIT]
Source code is also in this spoiler for quick access:
Spoiler
Hey orwell, I really wanted to use this program. I downloaded it and tried to open it, but when i do it closes. I opened the .exe and then it closes - It was a cmd type prompt? Please reply.
Orwell #18
Posted 26 September 2012 - 11:35 AM
All right then, my program and source file are in the attachment. Anyone can change it however they like and distribute it in any way. On condition of course, that I'm credited under the name Orwell in source code (if distributed) and readme/description.

Kazagistar, you seem motivated to expand your and mine project further on, so I would definitely like you to work off of it in the future. :D/>/> c++ really is the wise choice here. :P/>/>

If you have any questions about my (uncommented) source code, PM me. Or better, ask your questions here so everyone can benefit from it. :)/>/>

[EDIT]
Source code is also in this spoiler for quick access:
Spoiler
Hey orwell, I really wanted to use this program. I downloaded it and tried to open it, but when i do it closes. I opened the .exe and then it closes - It was a cmd type prompt? Please reply.

Indeed, you need to run it from command prompt. Make sure you're in the directory where my program is stored and then run 'cc-typer filename'.
I put a version up for Tekkit as an attachment.
tdlab #19
Posted 27 September 2012 - 01:15 AM
I tried it today, it wasnt working. I dont really know what u mean by runing 'cctyper filename'?
Could you make a video/ tutorial on how it works? I made a folder in my downloads called "Cc auto typer" In there i have the cc-typer.exe and a test.txt, When i open the exe, it automatically closes. I dont know why? Please reply, ~Tdlab.
Thanks again!
Orwell #20
Posted 27 September 2012 - 01:55 PM
You can't just run the program by double clicking. It's a command line program. Read the steps I pm'ed you carefully once again. You need to start by pressing 'the Windows key + R'. The run window will open, there you need to type 'cmd' and press enter. Now you're in the command prompt. From there, do 'cd C:blabla'. And finally do 'cc-typer test.txt'. It's just like the promp in CC…
tdlab #21
Posted 27 September 2012 - 08:17 PM
This Is Epic! Orwell you are a god!
Caradain #22
Posted 30 September 2012 - 03:50 AM
Hello there, how do i get your program to slow down its key strokes, I can not find a way of getting to your programming..I Have it working …. just it's too fast for the server I am or something. Be gentle with me I am a noob.

PS you guys are great.
Hexus_One #23
Posted 18 October 2012 - 07:31 AM
I /think/ you change DEF_KEY_SPACING to a larger number, such as 10.
Also, exactly how long is the time spacing (ie how much time would, say, 1000 take)?
CoolisTheName007 #24
Posted 19 October 2012 - 04:50 PM
Hi, I improved your program by:
-adding tab support (replaces tabs by fixed ammount of spaces);
-fixing a line that broke the window custom name;
-adding a sleep before typing the rm command, that kept loosing a 'm';
-allowing parameters to be set by arguments from the command line;
-added several try clauses with error descriptions for ease of use;
I concluded also that adding an extra encoding support would be redundant because ComputerCraft does not deals well with non-ascii characters.
I attach bellow the files I modified (extension .txt must be changed to .py) , which must replace the ones originally posted in order to work, the rest of the installation is necessary. Usage is described upon call with no arguments.

PS: Your program is great!!!
Orwell #25
Posted 19 October 2012 - 05:59 PM
I /think/ you change DEF_KEY_SPACING to a larger number, such as 10.
Also, exactly how long is the time spacing (ie how much time would, say, 1000 take)?

I believe your talking about my program? It has finally gotten his own thread. : ) Check it out here: http://www.computercraft.info/forums2/index.php?/topic/4864-cc-copy-your-solution-to-servers-without-http-api/
I will fix the bugs that CoolistheName007 posted there as soon as I've time (as you'll find there, key spacing is in ms).
CoolisTheName007 #26
Posted 19 October 2012 - 06:13 PM
I /think/ you change DEF_KEY_SPACING to a larger number, such as 10.
Also, exactly how long is the time spacing (ie how much time would, say, 1000 take)?

I believe your talking about my program? It has finally gotten his own thread. : ) Check it out here: http://www.computerc...thout-http-api/
I will fix the bugs that CoolistheName007 posted there as soon as I've time (as you'll find there, key spacing is in ms).
Well, I ended up looking at kazagistar program, because you didn't seem alive (I'm so impatient, sorry :P/>/>) and because I'm more familiar with Python.
Maybe inspecting kazagistar program will help you? At least the part with ^ and other characters. In his program, those were control characters for the API he used to type, so he had to make a workaround which consisted of surrounding them with proper control characters.
CoolisTheName007 #27
Posted 19 October 2012 - 08:47 PM
Just finished adding support for either file paths relative to the current directory, or absolute paths.
The Lua compression files, if generated, are still kept in the minecopy folder.
Included this change in the command line help responses.

Together with adding the minecopy directory path to the system Path environment variable, this allows to do from anywhere:
>minecopy.py [parameters changes] [file path]

Below is the file I modified (change exension to .py).
Orwell #28
Posted 20 October 2012 - 09:16 PM
I was responding to Hexus_One : ) Let's use this thread for the original program for now on. And I don't need to look at his code :)/>/> I just need time, I'm very busy with my thesis right now. :/ You could patch my program yourself :)/>/> hint, hint
CoolisTheName007 #29
Posted 05 November 2012 - 10:49 PM
Ok, I modified the below file (rename the extension to .py) to include a pause to prevent typing of long programs to be interrupted by server kicking for inactivity.
Also, I added the minecopy folder to my path (see kazagistar's post, the programmer who made minecopy) so I can access it from anywhere!
ttouch #30
Posted 07 January 2013 - 06:45 AM
can I uploaded on github? (of course all credit will be yours)
Curly_Bracket #31
Posted 24 November 2013 - 05:00 AM
Hi!
I've made pretty much the same thing, except in C, so it can be compiled on Windows without the need for Python or Lua.

I suggest to go see the source link if you are unfamiliar with command prompt.
The source is available here.
And the binary here.