Question

I have the below code where I am trying to get the selected text from an active windows and print it onto the console.

DWORD new12=0;
KEYBDINPUT* input = new KEYBDINPUT[key_count];
    if( GetGUIThreadInfo( new12, lpgui ) )
{
    target_window = lpgui->hwndFocus;
}
else
{
   // You can get more information on why the function failed by calling
   // the win32 function, GetLastError().
   std::cout<<"error1";
}
// We're sending two keys CONTROL and 'V'. Since keydown and keyup are two
// seperate messages, we multiply that number by two.

for( int i = 0; i < key_count; i++ )
{
    input[i].dwFlags = 0;
    //input[i].type = INPUT_KEYBOARD;
}

input[0].wVk = VK_CONTROL;
input[0].wScan = MapVirtualKey( VK_CONTROL, MAPVK_VK_TO_VSC );
input[1].wVk = 0x56; // Virtual key code for 'v'
input[1].wScan = MapVirtualKey( 0x56, MAPVK_VK_TO_VSC );

I have the above c++ code but it seems to be giving an error saying "error: MAPVK_VK_TO_VSC' was not declared in this scope" in the line input[0].wScan = MapVirtualKey( VK_CONTROL, MAPVK_VK_TO_VSC ); I wonder what is the problem here. I don't think this error is popping up because of any declaration problems. Can you please help me out here? Thank you.

Was it helpful?

Solution

MAPVK_VK_TO_VSC is a simple #define MAPVK_VK_TO_VSC (0), not even a constant, so it should be resolved on the preprocessing stage.

Either you've missed to include "winuser.h" before this code (in that case MapVirtualKey and VK_ constants will be undeclared too), or you have undefined WIN_VER somewhere (or defined it less than 0x400). Sometimes it's easy to forget that WIN_VER must be defined in hex, and with something like #define WINVER 500, you've got version less than 2.0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top