Wrong keycode on right arrow key?

Hi to everyone,
i'm almost new to arduino, but i expected to use the forum for something more complicated than this silly clue :frowning:

briefly explain scenario: Using an Arduino Mega and keyboard firmware hack.
(ignoring the hassle to going back and forth with firmware to test real results of serial write)
I'm remapping an old editing console from 90s', sony rm-450. totally bypassing original electronics and will map mechanical buttons as a button matrix etc. etc...(they are 32!!)
Its two jog/shuttles are optical encoders and made them working pretty fine.
The trouble occured when assigning keystrokes to components.
Finding the right keycodes (HID), left arrow (0x4f) is sent correctly, but right arrow (0x50) is wrong and once acting as keyboard that keycode is an ALT key, whatever keyboard layout i change. (checked with a character scanner) I tried to switch several keyboard layouts with no chance.
Honestly i ordered a Pro Micro for better keyboard related stuff. But by now i'm afraid this issue would remain.. any ideas?
thanks

You haven't posted your code,
you haven't posted your circuit.

We can't help if left completely ignorant like this... Please read the how to post posting and come back with all the necessary information.

Yes, actually right :grimacing: ...
the code:



uint8_t buf[8] = { 0 };

#define outputA 2
#define outputB 4
#define left_s  0x4f
#define right_s 0x50
#define stop_s  0x0e



int state = 1;
int mod;
int counter = 0;
int aState;
int aLastState;

void setup() 
{
  Serial.begin (9600);
  pinMode (outputA, INPUT);
  pinMode (outputB, INPUT);
 digitalWrite (outputA, 1);
  digitalWrite (outputB ,1);
  

/*delay(200);*/
  
  // Reads the initial state of the outputA
     aLastState = digitalRead(outputA);
}


void loop() {
  aState = digitalRead(outputA); // Reads the "current" state of the outputA
  
  // If the previous and the current state of the outputA are different, that means a Pulse has occured
  if (aState != aLastState) {
    // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
    if (digitalRead(outputB) != aState) {
      buf[0] = right_s;
       Serial.write(buf, 8);
      releaseKey();
     /* delay (100);*/
    }
    
     else  {
        buf[0] = left_s;
   
      Serial.write(buf, 8);
      releaseKey();
     /*  delay (100);*/
        /*if (digitalRead(outputB) == 0) {
          buf[1] = stop_s;
          Serial.write(buf, 8);
          releaseKey();
          
        }
*/      
    }
 
 
}
aLastState = aState; // Updates the previous state of the outputA with the current state
}
void releaseKey() 
{
  buf[0] = 0;
   buf[1] = 0;
  buf[2] = 0;
  Serial.write(buf, 8);  // Release key  
}
 
 

by now is very basic, just 2 digital input for encoder (clk/dt) and its power (3.3v or 5v, didn't make difference)
. if i don't solve this, won't connect any other button or anything to board.


by now i connected a standard rotary encoder for easier manipulation (and for checking if was a hardware issue but it isn't).

if i use a com-port to keyboard software bridge, left and right arrow on HID keycode 0x4f and 0x50 are seen as O and P. ok, i understand different coding. no problem.
forcing button mapping on NLE, it works as expected. but i don't want to use external apps to mantain cross-platform compatibility.
if i upload keyboard firmware on Mega, should find exact keycodes. and surprisingly, arrows don't stay both in place.
and if trying left/right arrow keycodes for serial input (37/39) a ' and % are displayed instead.

At this point i'm stuck.....

The HID Page 7 key codes are 79==0x4f for Keyboard RightArrow and 80==0x50 for Keyboard LeftArrow. You seem to have them reversed. That does not explain why your LeftArrow works and RightArrow doesn't.

Did you write a sketch to test that your encoder handling is working? It would be good to verify that you can detect clockwise and counter-clockwise movement.

Hi, the only sure things is encoder directions are correctly recognized, in fact if emulating keyboard with a serial bridge, jog works perfectly.

actually the situation got worse and maybe I posted code when trying swapping values, you can imagine i tried anything :grimacing::sweat_smile:...

Unfortunately the last try with keyboard firmware and technically with correct HID values produced even worse and different keystrokes :grimacing::grimacing:

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