Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

upper case kb_event!

Posted on 2007-11-28
5
928 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

861 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