I am trying to use Robot.js inside of a React.js application. I have Robot.js installed and can run it to get the results in a separate file. I cannot find a way to run Robot.js inside a React component because I get an error "robot.getMousePos()" is not a function. All I really need is the value of "hex". Is there a way to export the variable into my react component, Or even better run the Robot.js code in the same component without getting errors?
This is the Robot.js example:
const color = () => {
// Get pixel color under the mouse.
var robot = require("robotjs");
// Get mouse position.
var mouse = robot.getMousePos();
// Get pixel color in hex format.
var hex = robot.getPixelColor(mouse.x, mouse.y);
console.log("#" + hex + " at x:" + mouse.x + " y:" + mouse.y);
};
color();
it returns the value of "hex" which is equal to the hexidecimal color under the mouse at the given x and y coords (#1e1e1e at x:746 y:511)
I am trying to get that output into my React component whose code is here:
import React from "react";
const Robot = () => {
return (
<div>
<h1>Robot</h1>
</div>
);
};
export default Robot;