Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "stdio.h"
- #include "Windows.h"
- #include "psapi.h"
- #include "winuser.h"
- #include "strsafe.h"
- #define STRX 2
- #define STRY 10
- #define LINEHEIGHT 20
- static const HWND gh_hwndMain;
- static const HOOK h;
- #define DRAW(__x,__line_index,__format,...)\
- CHAR __szBuf[512];\
- StringCchPrintfA(__szBuf, 512,__format, __VA_ARGS__);\
- draw(__szBuf, STRX, STRY + (LINEHEIGHT * __line_index));
- typedef struct Hook
- {
- int nType;
- HOOKPROC hkprc;
- HHOOK hhook;
- } HOOK;
- void WINAPI draw(CHAR* string, int x, int y);
- LRESULT WINAPI MouseCallback(int nCode, WPARAM wParam, LPARAM lParam);
- LRESULT WINAPI KeyboardCallback(int nCode, WPARAM wParam, LPARAM lParam);
- void WINAPI sethooks();
- LPSTR* GetDrives();
- LPCSTR DefineDrive(LPCSTR driveName);
- void WINAPI draw(CHAR* string, int x, int y) {
- HDC hdc = GetDC(gh_hwndMain);
- size_t cch;
- HRESULT hResult = StringCchLengthA(string, 255 / sizeof(CHAR), &cch);
- if (FAILED(hResult))
- {
- }
- TextOutA(hdc, x, y, LPCSTR(string), cch);
- ReleaseDC(gh_hwndMain, hdc);
- }
- LRESULT WINAPI MouseCallback(int nCode, WPARAM wParam, LPARAM lParam) {
- MSLLHOOKSTRUCT* pMouseStruct = (MSLLHOOKSTRUCT*)lParam; // WH_MOUSE_LL struct
- if (nCode == 0) {
- if (pMouseStruct != NULL) {
- printf_s("Mouse Coordinates: x = %i | y = %i \n", pMouseStruct->pt.x, pMouseStruct->pt.y);
- }
- CHAR szBuf[255];
- CHAR szMsg[255] = "mouse click";
- HDC hdc = GetDC(gh_hwndMain);
- HRESULT hResult = StringCchPrintfA(szBuf, 255,
- "MOUSE - nCode: %d, msg: %s, x: %d, y: %d ",
- nCode, szMsg, pMouseStruct->pt.x, pMouseStruct->pt.y);
- size_t cch;
- DRAW(2, 0, "MOUSE - nCode: %d, msg: %s, x: %d, y: %d ",
- nCode, szMsg, pMouseStruct->pt.x, pMouseStruct->pt.y)
- //draw(szBuf, 2, strPos);
- switch (wParam) {
- case WM_LBUTTONUP: {
- printf_s("LEFT CLICK UP\n");
- }break;
- case WM_LBUTTONDOWN: {
- printf_s("LEFT CLICK DOWN\n");
- }break;
- }
- }
- return CallNextHookEx(h.hhook, nCode, wParam, lParam);
- }
- LRESULT WINAPI KeyboardCallback(int nCode, WPARAM wParam, LPARAM lParam) {
- if (nCode >= 0)
- {
- if (wParam == WM_KEYDOWN)
- {
- KBDLLHOOKSTRUCT kbdStruct = *((KBDLLHOOKSTRUCT*)lParam);
- switch (kbdStruct.vkCode)
- {
- default:
- DRAW(2, 1, "KEYBOARD - nCode: %d, keycode: %d, scancode: %d, time in minutes since system start: %d", nCode, kbdStruct.vkCode, kbdStruct.scanCode, (kbdStruct.time / 1000) / 60)
- break;
- }
- }
- }
- return CallNextHookEx(h.hhook, nCode, wParam, lParam);
- }
- static HOOK mousehook = { WH_MOUSE_LL, MouseCallback };
- static HOOK keyboardhook = { WH_KEYBOARD_LL, KeyboardCallback };
- void WINAPI sethooks() {
- mousehook.hhook = SetWindowsHookExW(mousehook.nType, mousehook.hkprc, NULL, 0);
- keyboardhook.hhook = SetWindowsHookExW(keyboardhook.nType, keyboardhook.hkprc, NULL, 0);
- }
- void slice(const char* str, char* result, size_t start, size_t end)
- {
- strncpy(result, str + start, end - start);
- }
- LPSTR* GetDrives() {
- CHAR drives[1024];
- DWORD len = GetLogicalDriveStringsA(1024, drives);
- LPSTR drives_list[128];
- int drives_list_index = 0;
- for (int drive_sym = 0, last = 0; drive_sym < len; drive_sym++) {
- if (drives[drive_sym] == NULL) {
- slice(drives, drives_list[drives_list_index++], last, drive_sym);
- last = drive_sym + 1;
- }
- }
- return drives_list;
- }
- LPCSTR DefineDrive(LPCSTR driveName) {
- DWORD types[8] = {
- DRIVE_UNKNOWN,
- DRIVE_NO_ROOT_DIR,
- DRIVE_REMOVABLE,
- DRIVE_FIXED,
- DRIVE_REMOTE,
- DRIVE_CDROM,
- DRIVE_RAMDISK,
- NULL
- };
- const char* sTypes[8] = {
- "DRIVE_UNKNOWN",
- "DRIVE_NO_ROOT_DIR",
- "DRIVE_REMOVABLE",
- "DRIVE_FIXED",
- "DRIVE_REMOTE",
- "DRIVE_CDROM",
- "DRIVE_RAMDISK",
- NULL
- };
- return (LPCSTR)sTypes[GetDriveTypeA(driveName)];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement