Hid device for editing

hey there i am making a hid device with a pro micro and i want to simulate a command for changing brush size and hardness in photoshop by holding the key alt and right mouse button together and dragging the mouse in left and right for changing brush size and forward and backward for changing it's hardness. can any one explain me the codes for this? ( i want to do this with a 5 pin rotary encoader )

Divide the project down
You need to look up

  • google - how to use your chosen rotary encoder , there maybe a library or examples for it . Get that working o. It’s own
    -then you need to work out how to write the characters you want on your chosen display .

No one is going to have the code for doing all this , you have to write it ! Post your attempts and people will help.

This not really a beginners project

hey i have done it but the problem is that when the key press is emulated for the alt key and the mouse left key and the left/right movement they are not being registered at the same time it basically start emulating the right click and left/right movement separately . which results into the movement of mouse and right click instead of the required hold of alt button and right mouse click and the left/right movement (i m using the 5 pin rotary encoder )

We need to see code and wiring then !

Here's a summary of the connections provided for the Arduino (pro micro) HID device:

LED Connections:

L1: Connected to pin A0
L2: Connected to pin A1
L3: Connected to pin A2

Single Switch Connection:
Connected to pin A3

Encoder A Connections:

SW pin: Connected to pin 2
DT pin: Connected to pin 3
CLK pin: Connected to pin 4

Encoder B Connections:

SW pin: Connected to pin 5
DT pin: Connected to pin 6
CLK pin: Connected to pin 7

Matrix Switch Connections:

Rows: R1 connected to pin 15, R2 connected to pin 14, R3 connected to pin 16
Columns: C1 connected to pin 8, C2 connected to pin 9, C3 connected to pin 10

#include <Keypad.h>
#include <Encoder.h>
#include <Bounce2.h>
#include "HID-Project.h"

// Encoder A
int SW_A = 2;
int DT_A = 3;
int CLK_A = 4;
Encoder volumeKnob_A(DT_A, CLK_A);
Bounce encoderButton_A = Bounce(SW_A, 10); // Adjust the debounce time as needed

// Encoder B
int SW_B = 5;
int DT_B = 6;
int CLK_B = 7;
Encoder volumeKnob_B(DT_B, CLK_B);
Bounce encoderButton_B = Bounce(SW_B, 10); // Adjust the debounce time as needed

// F10 switch
int SW_F10 = A3;

// LED pins
int LED1 = A0; // L1 LED
int LED2 = A1; // L2 LED
int LED3 = A2; // L3 LED

// Matrix switch pins
byte rowPins[] = {15, 14, 16};
byte colPins[] = {8, 9, 10};
const byte numRows = 3;
const byte numCols = 3;

char keys[numRows * numCols] = {
  '1', '2', '3',
  '4', '5', '6',
  '7', '8', '9'
};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, numRows, numCols);

int timeLimit = 500;
long oldPosition_A = -999;
int currentState = 0;
const int numStates = 3;

void setup() {
  pinMode(SW_A, INPUT_PULLUP); // Set encoder A switch pin as INPUT_PULLUP
  pinMode(SW_B, INPUT_PULLUP); // Set encoder B switch pin as INPUT_PULLUP
  pinMode(SW_F10, INPUT_PULLUP); // Set F10 switch pin as INPUT_PULLUP

  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);

  // Initialize the HID-Project library
  Consumer.begin();

  // LED Animation
  ledAnimation();
}

void ledAnimation() {
  // LED Animation on startup
  for (int i = 0; i < 3; i++) {
    digitalWrite(LED1, HIGH);
    delay(100);
    digitalWrite(LED1, LOW);
    delay(100);
    digitalWrite(LED2, HIGH);
    delay(100);
    digitalWrite(LED2, LOW);
    delay(100);
    digitalWrite(LED3, HIGH);
    delay(100);
    digitalWrite(LED3, LOW);
    delay(100);
  }
}

void ChangeState() {
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);

  currentState++;
  if (currentState >= numStates) {
    currentState = 0;
  }

  switch (currentState) {
    case 0:
      digitalWrite(LED1, HIGH);
      break;
    case 1:
      digitalWrite(LED2, HIGH);
      break;
    case 2:
      digitalWrite(LED3, HIGH);
      break;
  }

  delay(100);
}

void F1() {
  // Emulate a key combination of Ctrl, Shift, and Esc together
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press(KEY_LEFT_SHIFT);
  Keyboard.press(KEY_ESC);
  delay(100);
  Keyboard.releaseAll();
}

void F2() {
  // Emulate a key combination of Ctrl+A
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press('a');
  delay(100);
  Keyboard.releaseAll();
}

void F3() {
  // Emulate a key combination of Ctrl+C
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press('c');
  delay(100);
  Keyboard.releaseAll();
}

void F4() {
  // Emulate a key combination of Ctrl+X
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press('x');
  delay(100);
  Keyboard.releaseAll();
}

void F5() {
  // Emulate a key combination of Ctrl+V
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press('v');
  delay(100);
  Keyboard.releaseAll();
}

void F6() {
  // Emulate a key combination of Windows key and D
  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.press('d');
  delay(100);
  Keyboard.releaseAll();
}

void F7() {
  // Emulate a key combination of Ctrl, Windows key, and T
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.press('t');
  delay(100);
  Keyboard.releaseAll();
}

void F8() {
  // Emulate a key combination of Windows key and R
  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.press('r');
  delay(100);
  Keyboard.releaseAll();
}

void F9() {
  // Emulate a key combination of Windows key and E
  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.press('e');
  delay(100);
  Keyboard.releaseAll();
}

void Layout1(char button) {
  switch (button) {
    case '1':
      F1();
      break;
    case '2':
      F2();
      break;
    case '3':
      F3();
      break;
    case '4':
      F4();
      break;
    case '5':
      F5();
      break;
    case '6':
      F6();
      break;
    case '7':
      F7();
      break;
    case '8':
      F8();
      break;
    case '9':
      F9();
      break;
  }
}

void Layout2(char button) {
  // Layout 2 implementation
}

void Layout3(char button) {
  // Layout 3 implementation
}

void processKeypad(char key) {
  switch (key) {
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      Layout1(key);
      break;
  }
}

void loop() {
  // Check encoder A button
  encoderButton_A.update();
  if (encoderButton_A.fell()) {
    int fall = millis();
    while (!encoderButton_A.update()) {}
    if (encoderButton_A.rose()) {
      int rise = millis();
      if (rise - fall > timeLimit) {
        Consumer.write(MEDIA_NEXT);
      } else {
        Consumer.write(MEDIA_PLAY_PAUSE);
      }
    }
    Keyboard.releaseAll();
  }

  // Check encoder A rotation
  long newPosition_A = volumeKnob_A.read();
  if (newPosition_A != oldPosition_A) {
    if (newPosition_A > oldPosition_A) {
      Consumer.write(MEDIA_VOLUME_UP);
    } else {
      Consumer.write(MEDIA_VOLUME_DOWN);
    }
    oldPosition_A = newPosition_A;
  }

  // Check encoder B button
  encoderButton_B.update();
  if (encoderButton_B.fell()) {
    int fall = millis();
    while (!encoderButton_B.update()) {}
    if (encoderButton_B.rose()) {
      int rise = millis();
      if (rise - fall > timeLimit) {
        // Handle the button event for encoder B
      } else {
        // Handle the button event for encoder B
      }
    }
    Keyboard.releaseAll();
  }

  // Check F10 switch
  if (digitalRead(SW_F10) == LOW) {
    delay(20); // Debounce delay
    if (digitalRead(SW_F10) == LOW) {
      ChangeState();
      while (digitalRead(SW_F10) == LOW) {} // Wait for switch release
      delay(20); // Debounce delay
    }
  }

  // Check keypad keys
  char key = keypad.getKey();
  if (key) {
    processKeypad(key);
  }
}

this is the code

i removed it while i was debugging

no actually it's my fault i was doing that mouse thing yesterday and when i was not able to do that i removed it completely but yes i have to add it .
the shortcut is Alt + Right Click + Drag Horizontally . When dragging to the left using this shortcut, the brush will increase in size. By dragging to the right, the brush will decrease in size. and i want to do this with the encoder

Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.