nzadLithium
September 11th, 2007, 08:27 AM
Hey i'm trying to write a program that like teamspeak can catch keys even when they are not in focus.
I found a way to do it using things similar to a key logger.
I'm using this code
#include <iostream>
#include <sys/io.h>
#include <stdio.h>
using namespace std;
unsigned char c;
int i = 0;
int main( int argc, char *argv[] )
{
if(getuid() || getgid())
{
printf("Have to be root to perform a iopl()!\n");
exit(1);
}//perform root checks
if(iopl(3) == -1)
{
perror("iopl()");
printf("error!");
exit(1); //get required iopl level to access keyboard
}
do
{
c = NULL;
c = inb(0x60); //catch scan codes from keyboard
if (c != NULL)
cout << c << endl; //write scan code to screen
//fflush(0); //empty all??
}while (i == 0);
}
I'm not sure what fflush is meant to do here but im assuming its clearing all streams?
Anyways i ran this code and my computer threw a spazz. It started opening random things then it just stopped and nothing would respond so i held down the power button :S
I'm just trying to a program running in the background to receive the key signals (and still let the program in focus receive them as well).
What am I doing wrong???
I found a way to do it using things similar to a key logger.
I'm using this code
#include <iostream>
#include <sys/io.h>
#include <stdio.h>
using namespace std;
unsigned char c;
int i = 0;
int main( int argc, char *argv[] )
{
if(getuid() || getgid())
{
printf("Have to be root to perform a iopl()!\n");
exit(1);
}//perform root checks
if(iopl(3) == -1)
{
perror("iopl()");
printf("error!");
exit(1); //get required iopl level to access keyboard
}
do
{
c = NULL;
c = inb(0x60); //catch scan codes from keyboard
if (c != NULL)
cout << c << endl; //write scan code to screen
//fflush(0); //empty all??
}while (i == 0);
}
I'm not sure what fflush is meant to do here but im assuming its clearing all streams?
Anyways i ran this code and my computer threw a spazz. It started opening random things then it just stopped and nothing would respond so i held down the power button :S
I'm just trying to a program running in the background to receive the key signals (and still let the program in focus receive them as well).
What am I doing wrong???