Arduino Uno Mini Keypad issue

Hi All, I’ve been trying to create my own 2 key keyboard (for osu) which i will be scaling up to cherry mx switches soon (just prototype now) but i cant get it to stop repeating the key when its being held down, I would like to have it so that one press of the button only gives 1 “z” or 1 “x” keystroke to the pc
sorry for the confusion

uint8_t buf[8] = { 
  0 };

#define PIN_Z 5
#define PIN_X 6

int state = 1;

void setup() 
{
  Serial.begin(9600);
  pinMode(PIN_Z, INPUT);
  pinMode(PIN_X, INPUT);
  digitalWrite(PIN_Z, 1); 
  digitalWrite(PIN_X, 1);
  delay(200);
}

void loop() 
{
  state = digitalRead(PIN_Z);
  if (state != 1) {
    buf[2] = 29; 
    Serial.write(buf, 8);
    releaseKey();
  } 

  state = digitalRead(PIN_X);
  if (state != 1) {
    buf[2] = 27; 
    Serial.write(buf, 8);
    releaseKey();
  } 
}

void releaseKey() 
{
  buf[0] = 0;
  buf[2] = 0;
  Serial.write(buf, 8); 
  delay(100);
}

Moderator edit: CODE TAGS

OSU_BUTTON.ino (734 Bytes)

Take a look at the state change example in the IDE.

I Still don't really get it, I understand how it works now but i dont know how to integrate it with my current sketch, Sorry, Im kinda new to arduino

You need to send a key code only when a switch goes from not being closed, to being closed, NOT while the switch IS closed.

vegemalation:
I Still don't really get it, I understand how it works now but i dont know how to integrate it with my current sketch, Sorry, Im kinda new to arduino

You can't just look at the current state. You also have to store the state so you can look for a state change. Not "is the button pressed" but "did the button just change from unpressed to pressed".
Using one input pin per button will not easily scale to a full alphanumeric keyboard. You should start using the Keypad library before you add more keys.
If you always send a Release message immediately after sending the Press message your OS will never do the repeated key thing. It will also cause problems with capital letters since the Shift key will appear to be pressed and released before the letter key is pressed. You should probably send the Release message wen the key is released.

I'm Only using the two keys so i should be alright, Ill have a re read of the example and try the code again, It just takes a fair amount of time as i have to flash the hex file to the chip every time to check it