i am trying to implement a simple keylogger...
my code works fine and is able to detect simple keystrokes....
the problem that im experiencing is that whenever a key is pressed it remains pressed forever even after i release the key unless i press some key again...and if i try to move my mouse or use alt tab to move focus to another window then the entire operating system starts acting haywire...random stuff happens...random mouse clicks and random keypresses....

im using ubuntu...

#include<sys/io.h>
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<signal.h>

int check(char c)
{
	if (c==inb(0x60))
	{
		return 1;
	}
	else
	return 0;
}
void exitting()
{
	printf("Quitting");
	exit(0);
}
int main()
{
	int fail=0;
	int status_code=0;
	char c;
	
	//signal handler
	struct sigaction action;
	action.sa_handler=exitting;
	sigaction(SIGINT,&action,NULL);
	
	//CHECKING PERMISSIONS
	fail=ioperm(0x60,1,1);
	if (fail==-1)
	{
		printf("Permission Denied");
		return 0;
	}
	fail=ioperm(0x64,1,1);
	if (fail==-1)
	{
		printf("Permission Denied");
		return 0;
	}
	
	//populating keymap
	char *asciit[127];
	FILE *fp;
	if((fp = fopen("us_km", "r")) == NULL)
	{
		printf("Error opening map file");
		return 0;
	}
	int i;
	for(i = 1; !feof(fp); i++)
	{
		asciit[i] = (char *)malloc(127);
    	fgets(asciit[i], 127, fp);

		if(asciit[i][0] == '#')
		{
			i--;
   			continue;
    	}
  	}
	
	char *temp;
	//infinite loop
	while (1)
	{
		status_code=inb(0x64);
		if(status_code==20)
		{
			c=inb(0x60);
			if(((int)c)<=128 && ((int)c)>0)
				printf("Key Pressed : %s \n",asciit[c]);
				//printf("Value of c is %c\n",c);
			fflush(0);
			temp=asciit[c];
			status_code=0;
		}
		while(check(c))
		{		}
		usleep(100);
	}
	return 1;
}

What can I say...this isn't a hacking forum.

its not about hacking....this is purely for educational purposes...besides li nux wont run this script without root access...

i just wanna know whats going wrong ?

nvm .. i solved it myself...

so.. what was the problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.