rotary encoder to keyboard error

I'm using leonardo board
i want if encoder turn counterclockwise then press any keyboard button
and if encoder turn clockwise then press another keyboard button
and if encoder don'move release those keys
but i check my encoder, there is no error but if i turn the encoder more than 4 or lots then keep press button until shut off the arduino is ther any problem in my code?

#include <Encoder.h>
#include<Keyboard.h>
typedef struct{
byte KeyL;
byte KeyR;
long Old;
long Now;
int Wait;
int Current;
} ENCODER;

void EncoderRead(ENCODER* Enc);

void EncoderRead(ENCODER* Enc){
if ((Enc->Old != Enc->Now)) {
Enc->Current = millis();
if (Enc->Old < Enc->Now) {
Keyboard.press(Enc->KeyR);
}else{
Keyboard.press(Enc->KeyL);
}
}else if((int)(Enc->Current+Enc->Wait) <= millis()){
Keyboard.release(Enc->KeyL);
Keyboard.release(Enc->KeyR);
}
Enc->Old = Enc->Now;
}

ENCODER NovA ={0,0,0,0,0,0};

Encoder NovA_Pin(10,11);

void setup() {

NovA.Wait = 12;

//키 값 정의(아스키코드 기준)
NovA.KeyL = 'j';
NovA.KeyR = 'k';

Keyboard.begin();
Serial.begin(9600);
}

void loop() {
NovA.Now = NovA_Pin.read();
EncoderRead(&NovA);

}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

Values used with millis() should be 'unsigned long', not 'int' so change ENCODER.Current and ENCODER.Wait.

  if ((int)(Enc->Current + Enc->Wait) <= millis()) {

This should generally be written as:

  if (millis() - Enc->Current >= Enc->Wait) {

thx error fixed
plus sometimes when i change the turning position keyL and keyR press together...
but i want smooth change like jjjjjjjkkkkkkkjjjjkkkk
if i change novA.WAIT does it fixed?