?
Solved

upper case kb_event!

Posted on 2007-11-28
5
Medium Priority
?
961 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
[X]
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
  • 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 2000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

650 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