Code Monkey home page Code Monkey logo

raw_clientmouse's Introduction

RAW_ClientMouse

This program reads your mouse input raw and sends it to an arduino. It will also create a window to block all of your mouse input. To close it just press alt f4.

Use this for the sender (the arduino connected to the pc running this repo)

#include <Wire.h>
 
// Define Slave I2C Address
#define SLAVE_ADDR 9
 
byte bf[8];
void setup() {
 
  // Initialize I2C communications as Master
  Wire.begin();
  
  // Setup serial monitor
  Serial.begin(115200);
}
 
void loop() {
  if(Serial.available()){
    Serial.readBytes(bf, 8);
    // Write a charatre to the Slave
    Wire.beginTransmission(SLAVE_ADDR);
    Wire.write(bf[0]);
    Wire.write(bf[1]);
    Wire.write(bf[2]);
    Wire.write(bf[3]);
    Wire.write(bf[4]);
    Wire.write(bf[5]);
    Wire.write(bf[6]);
    Wire.write(bf[7]);
    Wire.endTransmission();
  }
}

Use this for the reciever:

#include <Wire.h>
#include "HID-Project.h"
byte bf[3];
// Slave I2C Address
#define SLAVE_ADDR 9

void setup() {
 
  // Initialize I2C communications as Slave
  Wire.begin(SLAVE_ADDR);
  // Function to run when data requested from master
  Wire.onRequest(requestEvent); 
  
  // Function to run when data received from master
  Wire.onReceive(receiveEvent);
  
  // Setup Serial Monitor 
  Serial.begin(115200);
  Mouse.begin();
}

void receiveEvent() {
  //Serial.println("receive");
  // Read while data received
  byte x[8] = {0, 0, 0, 0, 0, 0, 0, 0};
  Wire.readBytes(x, 8);

  int dx =  (int)x[0] + (int)bf[0]; 
  int dy =  (int)x[1] + (int)bf[1];
  Mouse.move(dx, dy, x[5]);
  
  if(x[2] != 0 || bf[2] != 0)
    Mouse.press();
  else
    Mouse.release();
    
  if(x[3] != 0)
    Mouse.press(MOUSE_RIGHT);
  else
    Mouse.release(MOUSE_RIGHT);
    
  if(x[4] != 0)
    Mouse.press(MOUSE_MIDDLE);
  else
    Mouse.release(MOUSE_MIDDLE);
    
  if(x[6] != 0)
    Mouse.press(MOUSE_PREV);
  else
    Mouse.release(MOUSE_PREV);
    
  if(x[7] != 0)
    Mouse.press(MOUSE_NEXT);
  else
    Mouse.release(MOUSE_NEXT);


    memset(bf, 0, 3);
}
void requestEvent() {
 
}

void loop() {
  if(Serial.available()){
    Serial.readBytes(bf, 3); //use whatever code you need here! This data will be received from the main pc.
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.