Solved

upper case kb_event!

Posted on 2007-11-28
5
901 Views
Last Modified: 2008-02-01
#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);
     
}

0
Comment
Question by:Troudeloup
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 20369481
What is your question here?
0
 

Author Comment

by:Troudeloup
ID: 20369521
the output is all in lower case


which is not string1,

hw do I correct it?
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 20372097
>>>> the output is all in lower case
You'll get upper case if you set the VK_SHIFT as well.

>>>> which is not string1

but?

Regards, Alex
0
 

Author Comment

by:Troudeloup
ID: 20386524
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);
     
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 20386819
>>>> 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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now