Link to home
Start Free TrialLog in
Avatar of Troudeloup
Troudeloup

asked on

upper case kb_event!

#include <windows.h>
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

void output ( string string1 );
void enter();

vector<HWND> vw; // array for HWND

BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
      char buf [1024];
      GetWindowText(hwnd,buf,1024);

      if(!strstr(buf,(char*)lParam)) return true;

       vw.push_back(hwnd);

      return true;
}

int main()
{
      EnumWindows(EnumWindowsProc,(LPARAM)"notepad");

      Sleep ( 5000 );
      
      for (vector<HWND>::iterator i = vw.begin(); i != vw.end(); ++i)
      {
      // *i   = hwnd
            
            string string1;
            string1 = "I am a Canadian!";
            cout << "output!" << endl;
            //enter ();
            output ( string1 );
            //zenter ();


      }

   return 0;
}


////////////////////////////////////////////
// send string -  working only in chat window and not
////////////////////////////////////////////




void output ( string string1 )
{
      int size = string1.size();

      for (int i = 0; i < size; ++i)
      {
         BYTE vk = LOBYTE(::MapVirtualKey(string1[i], 0));
 
         keybd_event(VkKeyScan(string1[i]),vk,0,0);
         keybd_event(VkKeyScan(string1[i]),vk,KEYEVENTF_KEYUP,0);
      }
     
}

 
void enter()
{
      BYTE vk = LOBYTE(::MapVirtualKey(VK_RETURN, 0));
 
         keybd_event(VK_RETURN,vk,0,0);
         keybd_event(VK_RETURN,vk,KEYEVENTF_KEYUP,0);
     
}

Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

What is your question here?
Avatar of Troudeloup
Troudeloup

ASKER

the output is all in lower case


which is not string1,

hw do I correct it?
ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
how do I fix this?



string string1 = "VK_RETURN";

BYTE vk = LOBYTE(::MapVirtualKey( string1, 0));
keybd_event( string1,vk,0,0);
keybd_event( string1,vk,KEYEVENTF_KEYUP,0);
     
>>>> how do I fix this?

You could try

void output ( string string1 )
{
      int size = string1.size();

      for (int i = 0; i < size; ++i)
      {
         char c = string1[i];   // the char
         unsigned short scan = VkKeyScan(c);  // the scan code for c
         unsigned char  vk  = (scan & 0xff);   // == LOBYTE(scan)
         unsigned char  sac = scan >> 8;      // == HIBYTE(scan)
         unsigned char  mvk = (unsigned char)MapVirtualKey(c, 0);
         if (sac & 1)   // shift must be pressed additionally
               keybd_event(VK_SHIFT, (unsigned char)MapVirtualKey(VK_SHIFT,0), 0, 0);

         keybd_event(vk, mvk, 0, 0);
         keybd_event(vk, mvk, KEYEVENTF_KEYUP, 0);

         if (sac & 1)   // shift must be released
               keybd_event(VK_SHIFT, (unsigned char)MapVirtualKey(VK_SHIFT,0), KEYEVENTF_KEYUP, 0);

      }
     
}

Note:

     (sac & 2)   would indicate the CTRL key was pressed additionally
     (sac & 4)   would indicate the ALT key was pressed additionally