Skip to content

Commit dc8e820

Browse files
author
Simon Hofmann
committed
Initial commit
0 parents  commit dc8e820

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+10427
-0
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!--- Provide a general summary of the issue in the Title above. -->
2+
3+
## Expected Behavior
4+
<!--- If you're describing a bug, tell us what should happen. -->
5+
<!--- If you're suggesting a change/improvement, tell us how it should work. -->
6+
7+
## Current Behavior
8+
<!--- If describing a bug, tell us what happens instead of the expected behavior. -->
9+
<!--- If suggesting a change/improvement, explain the difference from current behavior. -->
10+
11+
## Possible Solution
12+
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
13+
<!--- or ideas how to implement the addition or change. -->
14+
15+
## Steps to Reproduce (for bugs)
16+
<!--- Please provide an unambiguous set of steps to reproduce this bug. -->
17+
<!--- Include code to reproduce. -->
18+
1.
19+
2.
20+
3.
21+
4.
22+
23+
## Context
24+
<!--- How has this issue affected you? What are you trying to accomplish? -->
25+
<!--- Providing context helps us come up with a solution that is most useful in the real world. -->
26+
27+
## Your Environment
28+
<!--- Include as many relevant details about the environment you experienced the bug in. -->
29+
* RobotJS version:
30+
* Node.js version:
31+
* npm version:
32+
* Operating System:

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build/
2+
node_modules/
3+
prebuilds/
4+
.idea
5+
.vscode

.travis.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- "10"
5+
- "11"
6+
- "12"
7+
8+
os:
9+
- linux
10+
- osx
11+
12+
cache:
13+
directories:
14+
- node_modules
15+
16+
git:
17+
depth: 5
18+
19+
addons:
20+
apt:
21+
sources:
22+
- ubuntu-toolchain-r-test
23+
packages:
24+
- libx11-dev
25+
- zlib1g-dev
26+
- libpng12-dev
27+
- libxtst-dev
28+
- g++-4.8
29+
- gcc-4.8
30+
31+
before_install:
32+
# print versions
33+
- node --version
34+
- npm --version
35+
36+
# use g++-4.8 on Linux
37+
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then export CXX=g++-4.8; fi
38+
39+
# before_script:
40+
# Start xvfb
41+
# - if [[ $TRAVIS_OS_NAME == "linux" ]]; then export DISPLAY=:99.0; fi
42+
# - if [[ $TRAVIS_OS_NAME == "linux" ]]; then sh -e /etc/init.d/xvfb start; fi
43+
44+
install:
45+
- npm install
46+
47+
script:
48+
- npm run build:release
49+
50+
# after_success:
51+
# - if [[ $TRAVIS_TAG != "" ]]; then npm run prebuild -- -u $GITHUB_TOKEN; fi

CMakeLists.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
set(CMAKE_CXX_STANDARD 17)
3+
4+
project(libnut)
5+
6+
# Source
7+
set(SOURCE_FILES "src/libnut.cc" "src/deadbeef_rand.c" "src/mouse.c" "src/keypress.c" "src/keycode.c" "src/screen.c" "src/screengrab.c" "src/snprintf.c" "src/MMBitmap.c")
8+
if (LINUX)
9+
set(SOURCE_FILES "${SOURCE_FILES}" "src/xdisplay.c")
10+
endif()
11+
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
12+
13+
# Includes
14+
include_directories("${CMAKE_SOURCE_DIR}/src/include")
15+
16+
set(LIBS "")
17+
set(INCLUDES "")
18+
19+
# External libs
20+
if (APPLE)
21+
message(STATUS "macOS build")
22+
set(LIBS "${LIBS}" "-framework ApplicationServices")
23+
set(LIBS "${LIBS}" "-framework Carbon")
24+
set(LIBS "${LIBS}" "-framework CoreFoundation")
25+
set(LIBS "${LIBS}" "-framework OpenGL")
26+
elseif (WIN32)
27+
message(STATUS "Windows build")
28+
elseif (LINUX)
29+
message(STATUS "Linux build")
30+
set(LIBS "${LIBS}" "-lpng")
31+
set(LIBS "${LIBS}" "-lz")
32+
set(LIBS "${LIBS}" "-lX11")
33+
set(LIBS "${LIBS}" "-lXtst")
34+
endif()
35+
36+
set(CMAKE_C_FLAGS "-Wall -Wparentheses -Winline -Wbad-function-cast -Wdisabled-optimization")
37+
set(CMAKE_C_FLAGS_RELEASE "-O3")
38+
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
39+
message(STATUS "No MSVC compiler in use, adding compile flags -Wextra")
40+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
41+
endif()
42+
43+
# add_compile_definitions(NAPI_CPP_EXCEPTIONS)
44+
45+
# cmake-js
46+
set(INCLUDES ${INCLUDES} ${CMAKE_JS_INC})
47+
set(LIBS ${LIBS} ${CMAKE_JS_LIB})
48+
message(STATUS "Libs: ${LIBS}")
49+
50+
# N-API
51+
# target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/node_modules/node-addon-api")
52+
53+
# Change suffix to *.node
54+
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
55+
56+
# BUILD
57+
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDES})
58+
target_link_libraries(${PROJECT_NAME} ${LIBS})

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Disclaimer
2+
3+
This project if based on [octaImage/robotjs](https://github.com/octalmage/robotjs) and is used internally at [nut-tree/nut.js](https://github.com/nut-tree/nut.js).
4+
5+
## Building
6+
7+
Please ensure you have the required dependencies before installing:
8+
9+
* Windows
10+
* windows-build-tools npm package (`npm install --global --production windows-build-tools` from an elevated PowerShell or CMD.exe)
11+
* Mac
12+
* Xcode Command Line Tools.
13+
* Linux
14+
* cmake
15+
* A C/C++ compiler like GCC.
16+
* libxtst-dev and libpng++-dev (`sudo apt-get install libxtst-dev libpng++-dev`).
17+
18+
### Release build
19+
20+
```
21+
npm install
22+
npm run build:release
23+
```
24+
25+
Installation and build on Windows
26+
27+
```
28+
npm install
29+
npm run build:release:win
30+
```
31+
32+
### Debug build
33+
34+
```
35+
npm install
36+
npm run build:debug
37+
```
38+
39+
Installation and build on Windows
40+
41+
```
42+
npm install
43+
npm run build:debug:win
44+
```

appveyor.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# http://www.appveyor.com/docs/appveyor-yml
2+
3+
environment:
4+
matrix:
5+
# node.js
6+
- nodejs_version: 10
7+
- nodejs_version: 11
8+
- nodejs_version: 12
9+
10+
cache:
11+
- node_modules
12+
13+
clone_depth: 5
14+
15+
platform:
16+
- x86
17+
- x64
18+
19+
# Install scripts. (runs after repo cloning)
20+
install:
21+
- ps: Install-Product node $env:nodejs_version $env:platform
22+
- npm -g install npm
23+
- set PATH=%APPDATA%\npm;%PATH%
24+
# Typical npm stuff.
25+
- npm install
26+
- npm run build:release:win
27+
28+
# test_script:
29+
# Output useful info for debugging.
30+
# - node --version
31+
# - npm --version
32+
# run tests
33+
# - npm test
34+
35+
on_success:
36+
- IF defined APPVEYOR_REPO_TAG_NAME npm run prebuild -- -u %GITHUB_TOKEN%
37+
38+
build: off
39+
version: "{build}"

index.d.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export interface Bitmap {
2+
width: number;
3+
height: number;
4+
image: any;
5+
byteWidth: number;
6+
bitsPerPixel: number;
7+
bytesPerPixel: number;
8+
colorAt(x: number, y: number): string;
9+
}
10+
11+
export interface Screen {
12+
capture(x?: number, y?: number, width?: number, height?: number): Bitmap;
13+
}
14+
15+
export function setKeyboardDelay(ms: number): void;
16+
export function keyTap(key: string, modifier?: string | string[]): void;
17+
export function keyToggle(
18+
key: string,
19+
down: string,
20+
modifier?: string | string[]
21+
): void;
22+
export function typeString(string: string): void;
23+
export function typeStringDelayed(string: string, cpm: number): void;
24+
export function setMouseDelay(delay: number): void;
25+
export function moveMouse(x: number, y: number): void;
26+
export function moveMouseSmooth(x: number, y: number): void;
27+
export function mouseClick(button?: string, double?: boolean): void;
28+
export function mouseToggle(down?: string, button?: string): void;
29+
export function dragMouse(x: number, y: number): void;
30+
export function scrollMouse(x: number, y: number): void;
31+
export function getMousePos(): { x: number; y: number };
32+
export function getPixelColor(x: number, y: number): string;
33+
export function getScreenSize(): { width: number; height: number };
34+
35+
export const screen: Screen;

index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var libnut = require("bindings")("libnut.node");
2+
3+
module.exports = libnut;
4+
5+
module.exports.screen = {};
6+
7+
function bitmap(width, height, byteWidth, bitsPerPixel, bytesPerPixel, image) {
8+
this.width = width;
9+
this.height = height;
10+
this.byteWidth = byteWidth;
11+
this.bitsPerPixel = bitsPerPixel;
12+
this.bytesPerPixel = bytesPerPixel;
13+
this.image = image;
14+
15+
this.colorAt = function(x, y) {
16+
return libnut.getColor(this, x, y);
17+
};
18+
}
19+
20+
module.exports.screen.capture = function(x, y, width, height) {
21+
//If coords have been passed, use them.
22+
if (
23+
typeof x !== "undefined" &&
24+
typeof y !== "undefined" &&
25+
typeof width !== "undefined" &&
26+
typeof height !== "undefined"
27+
) {
28+
b = libnut.captureScreen(x, y, width, height);
29+
} else {
30+
b = libnut.captureScreen();
31+
}
32+
33+
return new bitmap(
34+
b.width,
35+
b.height,
36+
b.byteWidth,
37+
b.bitsPerPixel,
38+
b.bytesPerPixel,
39+
b.image
40+
);
41+
};

0 commit comments

Comments
 (0)