Hey everyone! I've used AutoIt for many years and finally decided to try to convert one of my scripts into C++. Things are nearly done, but I am having issues with the SendInput() API. Basically I am try to rewrite this script at this post #631512 With my C++ project I cannot send Uppercase characters and special keys like Shift, Ctrl, and ALT. Any idea what I am doing wrong, or any suggestions? #define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x1337
#include <windows.h>
#include <iostream>
#include <winable.h> /* Dev-C++ specific */
using namespace std;
void GenerateKey(BYTE vk);
void SendText(char *szText);
void keepAlive();
LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam);
//char *szText = "Test";
/* HWND = "Window Handle" */
HWND hWnd = FindWindow(0, "Untitled - Notpad");
HHOOK keyboardHook;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardHookProc, hInstance, 0);
keepAlive();
UnhookWindowsHookEx(keyboardHook);
return 0;
}
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;
}
void SendText(char *szText)
{
for (int i=0;i<strlen(szText);i++)
{
GenerateKey( (UCHAR) VkKeyScan( szText[i] ) );
}
}
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)
{
// Invisible keys
case VK_SCROLL:
{
//SendText(szText);
SendText("Some text to send.");
}
break;
/* case VK_LSHIFT: // <These hotkeys don't matter at the moment because I am trying to get things working as is, but will enable them after
break;
case VK_RSHIFT:
cout << "[RSHIFT]";
break;
case VK_LCONTROL:
cout << "[LCTRL]";
break;
case VK_RCONTROL:
cout << "[RCTRL]";
break;
case VK_INSERT:
cout << "[INSERT]";
break;
case VK_END:
cout << "[END]";
break;
case VK_PRINT:
cout << "[PRINT]";
break;
*/
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
void keepAlive()
{
MSG message;
while (GetMessage(&message,NULL,0,0))
{
TranslateMessage( &message );
DispatchMessage( &message );
}
}