RFID and Computer Login

I Have MFRC-522 RFID Module and a Arduino Uno and i Have Programmed Arduino Uno to send Keystrokes by upgrading firmware of Atmega16U2 and i was successful but when i just merge two codes i am able use it but when i scan the default card and for test i do it in notepad everything goes wrong like all button press themselves and open up different applications and mouse and keyboard does not work untill i restart the computer

so how to solve this problem

Please Help

so how to solve this problem

It seems such a very obvious thing to say, but how about posting your code?

#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 9
#define RST_PIN 10
 uint8_t buf[8] = {
0 };
MFRC522 mfrc522 ( SS_PIN, RST_PIN ) ;
String readid;
String card1="7A 6D 03 6B";                //Change this value to the UID of your card.
 
void setup( ) 
{
Serial.begin(9600);
randomSeed(analogRead(0));
delay(200);
 SPI.begin();
 mfrc522.PCD_Init();
}

void temp(byte *buffer, byte bufferSize)//function to store card uid as a string datatype.
{
  readid="";
  for(byte i = 0;i<bufferSize; i++)
  {
    readid=readid+String(buffer[i], HEX);
  }
}
void loop( ) 
{
 if(!mfrc522.PICC_IsNewCardPresent())
 {
  return;
 }
 if(!mfrc522.PICC_ReadCardSerial()) 
 {
  return;
 }
 mfrc522.PICC_DumpToSerial(&(mfrc522.uid));  // Display card details in serial Monitor.
 temp(mfrc522.uid.uidByte, mfrc522.uid.size);
 if(readid==card1)
 { 
  delay(50);

buf[0] = 0;
buf[2] = 0x13; // letter p
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x04; // letter a
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x16; // letter s
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x16; // letter S
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x1A; // letter w
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x12; // letter o
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x15; // letter r
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x07; // letter d
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x28; // letter Enter
Serial.write(buf, 8);
releaseKey();
 }
 else
 {
  return;
 } 
}
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
}

Your "." key doesn't work. Here are some extras: ..........

jremington:
Your "." key doesn't work. Here are some extras: ..........

i did not get you what key are you talking about the rfid card uid or anything else

The "." key is rather similar to the "a", "b", "c" and "1", "2", "3", etc. keys, but instead, it makes a ".", which is often used to end a sentence.

everything goes wrong like all button press themselves and open up different applications and mouse and keyboard does not work untill i restart the computer

That is because you have written it like that, when a card with the number stored in the variable card1 is presented you just send a load of stuff to the computer.is that what you want to do? If not then what do you want to do? Please explain.

Notice that last sentence ended in a . Which is sometimes called a full stop or period.
It makes a bunch of words easy to read. If you can’t use them in English then you are going to struggle in writing code because the compiler is not as smart as people and can easily be confused.

Grumpy_Mike:
Notice that last sentence ended in a . Which is sometimes called a full stop or period.
It makes a bunch of words easy to read. If you can’t use them in English then you are going to struggle in writing code because the compiler is not as smart as people and can easily be confused.

what you said was right when variable card is scanned then just send keystorkes to computer

i am not getting about which line the error is there or where is the error it justs complies it and uploads but doesn't work what should i fix in the code
i have given the keyboard numbers from a pdf file

USBKeyScan PDF

Once a program compiles that means the computer understands or thinks it understands your instructions. The fact that your instructions do not do what you hoped it would is your error.

As you don’t say what you want this code to do then no one can help you with how to make the code do what is in your head because we can’t read what is in your head. Without full stops we can barely read the English you wrote.

So I will ask again, what do you want the code to do?

Grumpy_Mike:
what do you want the code to do?

What i want is Login to Computer using RFID Card

The key commands are correct and everything i checked was right i just want is to type the password when the rfid card is scanned

So where is the typed in password coming from?
are you going to attach a keyboard to your Arduino?

no i am not going to attach any keyboard i am reprogramming the programming chip the atmega16u2 from usb to serial

to

keyboard 0.3.hex

and i tested it using this code by pressing a button

/* Arduino USB HID Keyboard Demo
* Random Key/Random Delay
*/
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */

void setup()
{
    pinMode(5, INPUT_PULLUP);

Serial.begin(9600);
randomSeed(analogRead(0));
delay(200);
}

void loop()
{if(digitalRead(5)==LOW){

delay(50);

buf[0] = 0;
buf[2] = 0x13; // letter p
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x04; // letter a
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x16; // letter s
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x16; // letter S
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x1A; // letter w
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x12; // letter o
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x15; // letter r
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x07; // letter d
Serial.write(buf, 8);
releaseKey();

delay(50);

buf[0] = 0;
buf[2] = 0x28; // letter Enter
Serial.write(buf, 8);
releaseKey();
}
}

void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
}

and the loop command is in the first code i gave when the rfid scans it presses these keys