Hey everyone,
I'm a beginner to C++ and I am having some issues with ease of outputting strings through the SendInput() API.
Currently I am stuck at outputting one key at a time which in itself isn't a problem, but gets tedious if you have 9 different strings with up to 15 characters each. My goal is to be able to set a few hotkeys that call the SendMessage() function that can send a sentence.
This is what I have currently.
As you can see this can get tedious.Code:#define WIN32_LEAN_AND_MEAN #define _WIN32_WINNT 0x1337 #include <windows.h> #include <winable.h> /* GNU GCC specific */ using namespace std; HHOOK keyboardHook; void GenerateKey(BYTE vk) { INPUT Input; ZeroMemory(&Input, sizeof(Input)); Input.type = INPUT_KEYBOARD; Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY; Input.ki.wVk = vk; SendInput(1, &Input, sizeof(INPUT)); return; } LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) { PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) (lParam); // If key is being pressed if (wParam == WM_KEYDOWN) { switch (p->vkCode) { //Define Hotkeys here case VK_SCROLL: { GenerateKey((UCHAR)VkKeyScan('C')); GenerateKey((UCHAR)VkKeyScan('o')); GenerateKey((UCHAR)VkKeyScan('d')); GenerateKey((UCHAR)VkKeyScan('i')); GenerateKey((UCHAR)VkKeyScan('n')); GenerateKey((UCHAR)VkKeyScan('g')); GenerateKey((UCHAR)VkKeyScan(' ')); GenerateKey((UCHAR)VkKeyScan('i')); GenerateKey((UCHAR)VkKeyScan('s')); GenerateKey((UCHAR)VkKeyScan(' ')); GenerateKey((UCHAR)VkKeyScan('f')); GenerateKey((UCHAR)VkKeyScan('u')); GenerateKey((UCHAR)VkKeyScan('n')); GenerateKey((UCHAR)VkKeyScan('.')); GenerateKey((UCHAR)VkKeyScan('\n')); /* enter key */ } break; case VK_INSERT: break; case VK_END: break; case VK_PRINT: break; */ } } return CallNextHookEx(NULL, nCode, wParam, lParam); } void keepAlive() { MSG message; while (GetMessage(&message,NULL,0,0)) { TranslateMessage( &message ); DispatchMessage( &message ); } } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardHookProc, hInstance, 0); keepAlive(); UnhookWindowsHookEx(keyboardHook); return 0; }
Is there a way to do something like
Code:GenerateKey((UCHAR)VkKeyScan('Coding Is Fun'));



LinkBack URL
About LinkBacks


