diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae8beaa --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.idea +.vs +dist +packages +x64 +[Dd]ebug +[Rr]elease +StyleCop.Cache \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8d77987 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2014 YANG YUAN + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..7d4a11b --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +Rabbit +====== +![Build Status](https://6941987.visualstudio.com/_apis/public/build/definitions/11759935-74e5-4a06-843f-9794d369a62d/2/badge) + +## News + +- Rabbit re-init. (Dec 29, 2017) +- Rabbit packages first release. (Dec 20, 2017) +- Initial commit. (Dec 3, 2014). + +## Purposes and Features + +Rabbit is designed to use programs to simulate human inputs. Which might be useful in some boring repeating tasks or game bots. + +This project contains two sub-projects: + + - Rabbit App: An application with embedded scripting support, an alternative of QuickMacro. + - Rabbit-Bot Packages: Packages for Python (PyPI), JavaScript (NPM). + +## Usage + +### Rabbit App +F7/F8 will start/end the script. +The application will search script.py/script.js/script.lua in order, but only one script will run. + +### Rabbit-Bot Packages + +#### PyPI + +https://pypi.python.org/pypi/rabbit-bot/ + +`pip install rabbit-bot` + +#### NPM + +https://www.npmjs.com/package/rabbit-bot + +`npm install rabbit-bot` diff --git a/samples/script.py b/samples/script.py new file mode 100644 index 0000000..b6bbd87 --- /dev/null +++ b/samples/script.py @@ -0,0 +1,32 @@ +import rabbit + +# Press left Window key +rabbit.keyboard_press_vkey(0x5B) +rabbit.sleep(1000) + +# Input 'Notepad' +rabbit.press('N') +rabbit.input('tepad') +rabbit.sleep(1000) + +# Press Enter key +rabbit.keyboard_press_vkey(0x0D) +rabbit.sleep(1000) + +# Do input +rabbit.input('Hello Rabbit!\n') +rabbit.sleep(1000) +rabbit.input('你好兔子!\n') +rabbit.sleep(1000) + +# Find current Window +notepad = rabbit.window_find_focus() +l, t, r, b = rabbit.window_get_rect(notepad) + +# Move mouse do doubleclick and then input more +rabbit.moveto(int(l + (r - l)/2), int(t + (b - t)/2)) +rabbit.doubleclick() +rabbit.sleep(500) +rabbit.input('Window location: %d %d %d %d\n' % (l, t, r, b)) +rabbit.keyboard_press_vkey(0x0D) +rabbit.keyboard_press_vkey(0x0D) diff --git a/src/app/Rabbit.sln b/src/app/Rabbit.sln new file mode 100644 index 0000000..cbd2e08 --- /dev/null +++ b/src/app/Rabbit.sln @@ -0,0 +1,32 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.15 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Rabbit", "Rabbit.vcxproj", "{7442468C-C7CC-4122-833F-73D613685502}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7442468C-C7CC-4122-833F-73D613685502}.Debug|Win32.ActiveCfg = Debug|Win32 + {7442468C-C7CC-4122-833F-73D613685502}.Debug|Win32.Build.0 = Debug|Win32 + {7442468C-C7CC-4122-833F-73D613685502}.Debug|x64.ActiveCfg = Debug|x64 + {7442468C-C7CC-4122-833F-73D613685502}.Debug|x64.Build.0 = Debug|x64 + {7442468C-C7CC-4122-833F-73D613685502}.Debug|x86.ActiveCfg = Debug|Win32 + {7442468C-C7CC-4122-833F-73D613685502}.Debug|x86.Build.0 = Debug|Win32 + {7442468C-C7CC-4122-833F-73D613685502}.Release|Win32.ActiveCfg = Release|Win32 + {7442468C-C7CC-4122-833F-73D613685502}.Release|Win32.Build.0 = Release|Win32 + {7442468C-C7CC-4122-833F-73D613685502}.Release|x64.ActiveCfg = Release|x64 + {7442468C-C7CC-4122-833F-73D613685502}.Release|x64.Build.0 = Release|x64 + {7442468C-C7CC-4122-833F-73D613685502}.Release|x86.ActiveCfg = Release|Win32 + {7442468C-C7CC-4122-833F-73D613685502}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/app/Rabbit.vcxproj b/src/app/Rabbit.vcxproj new file mode 100644 index 0000000..68b5a72 --- /dev/null +++ b/src/app/Rabbit.vcxproj @@ -0,0 +1,161 @@ + + + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + 15.0 + {7442468C-C7CC-4122-833F-73D613685502} + Rabbit + 10.0.16299.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + ..\core;%(AdditionalIncludeDirectories) + + + + + Level3 + Disabled + true + ..\core;%(AdditionalIncludeDirectories) + + + + + Level3 + MaxSpeed + true + true + true + ..\core;%(AdditionalIncludeDirectories) + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + ..\core;%(AdditionalIncludeDirectories) + + + true + true + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + \ No newline at end of file diff --git a/src/app/app.cpp b/src/app/app.cpp new file mode 100644 index 0000000..e368d85 --- /dev/null +++ b/src/app/app.cpp @@ -0,0 +1,108 @@ +#include "app.h" +#include +#include +#include +#include + +bool load_script(LPCTSTR path, LPSTR &buffer, DWORD &length) +{ + // LOAD FILE AND CONVERT TO UTF8 + HANDLE hFile = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile == INVALID_HANDLE_VALUE) return false; + + length = GetFileSize(hFile, NULL); + if (length) + { + LPSTR cache = new char[length + 1]; + DWORD dwRead; + if (ReadFile(hFile, cache, length, &dwRead, NULL)) + { + cache[length] = _T('\000'); + buffer = (LPSTR)cache; + if (cache[0] == '\xEF' && cache[1] == '\xBB' && cache[2] == '\xBF') { + LPSTR result = new char[length-2]; + strncpy_s(result, length - 2, cache + 3, length - 2); + buffer = result; + delete cache; + } else if (IsTextUnicode(cache, length, NULL)) + { + LPSTR result = new char[length+1]; + WideCharToMultiByte(CP_UTF8, 0, (WCHAR*)cache, length, result, length, NULL, NULL); + buffer = result; + delete cache; + } + } + else + { + delete[] cache; + } + } + CloseHandle(hFile); + return true; +} + +void rabbit_init_lua(lua_State * L); +PyMODINIT_FUNC PyInit_rabbit(); +v8::Local rabbit_javascript(v8::Isolate* isolate); + +static v8::Isolate * isolate = NULL; + +void rabbit_string(RABBIT_MODE mode, char * script) +{ + if (mode == RABBIT_MODE_LUA) { + lua_State * L = luaL_newstate(); + luaL_openlibs(L); + rabbit_init_lua(L); + luaL_loadstring(L, script); + int status = lua_pcall(L, 0, LUA_MULTRET, 0); + lua_close(L); + } + else if(mode == RABBIT_MODE_JAVASCRIPT) { + using namespace v8; + + if (isolate == NULL) { + V8::InitializeICU(".\\icudtl.dat"); + V8::InitializeExternalStartupData("."); + Platform* platform = platform::CreateDefaultPlatform(); + V8::InitializePlatform(platform); + + v8::V8::Initialize(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); + isolate = Isolate::New(create_params); + } + + Isolate::Scope isolate_scope(isolate); + HandleScope handle_scope(isolate); + v8::Local global = v8::ObjectTemplate::New(isolate); + Local rabbit = rabbit_javascript(isolate); + global->Set(String::NewFromUtf8(isolate, "rabbit", NewStringType::kNormal).ToLocalChecked(), rabbit); + + Local context = Context::New(isolate, NULL, global); + Context::Scope context_scope(context); + Local source = String::NewFromUtf8(isolate, script, NewStringType::kNormal).ToLocalChecked(); + Local