Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VK_RETURN

Posted on 2007-11-30
15
Medium Priority
?
1,090 Views
Last Modified: 2008-02-01
string string1 = "VK_RETURN";

BYTE vk = LOBYTE(::MapVirtualKey( string1, 0));
keybd_event( string1,vk,0,0);
keybd_event( string1,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
  • 8
  • 7
15 Comments
 
LVL 13

Expert Comment

by:josgood
ID: 20386638
What is your question?
0
 

Author Comment

by:Troudeloup
ID: 20386650
well, I want to use

keybd_event() to press keyboard key SHIFT.


but i don't want to write a function for that:


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





plus, I think it's possible to contain VK_ENTER

like this

string1[6] = VK_ENTER





0
 

Author Comment

by:Troudeloup
ID: 20386660
uh sorry, it's this


      BYTE vk = LOBYTE(::MapVirtualKey( VK_RETURN, 0));
      keybd_event( VK_RETURN,vk,0,0);
      keybd_event( VK_RETURN,vk,KEYEVENTF_KEYUP,0);
      
      
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 13

Expert Comment

by:josgood
ID: 20386679
If I remember correctly, you  can simulate the shift key with
keybd_event(VK_SHIFT,1,0,0);
keybd_event(YourKeyHere,1,0,0);
keybd_event(VK_SHIFT,1,KEYEVENTF_KEYUP,0);

and the return key with
keybd_event(VK_RETURN,1,0,0);
keybd_event(VK_RETURN,1,KEYEVENTF_KEYUP,0);

Give me a little time to put a test program together.

Joe
0
 

Author Comment

by:Troudeloup
ID: 20386680
more precisely:


string = "HELLO"

I want it to be upper case letter when it's printed.

this now it is lower case.
0
 
LVL 13

Expert Comment

by:josgood
ID: 20386687
OK
0
 

Author Comment

by:Troudeloup
ID: 20386689
stop, please try to do this


string = "HellO"


keyboard_event to send upper and lower case letter.



another example is 1 and !

the current code would send only 1 and never !

I am trying to write a parser so that





string string1 ="Hello"

should be like this


string2 =

[0] = shift
[1] = h
[2] = shift up
[3] = e
[4] = l
[5] = o
[6] = o


If string[n] == "H"

test is c++ can tell the difference between upper and lowercase



plan:



loop
{
if string[n] == upper case
string2[n] = shift
string2[n+1] = string1[n]
string2[n+2] = shift
}

send string2 to output



0
 

Author Comment

by:Troudeloup
ID: 20386694
ignore this line


If string[n] == "H"

test is c++ can tell the difference between upper and lowercase


that's my own note  ;p
0
 

Author Comment

by:Troudeloup
ID: 20386695
if the case of 1 would !

of course the solution is also

shift down
1
shift up

and it should be dealt by the parser, if one is needed. ( i am not sure)
0
 
LVL 13

Expert Comment

by:josgood
ID: 20386713
I'm a little confused, but it seems like you want
1)  A way to mark where the shifted character(s) is/are in a string
2)  A way to send the shifted characters

Am I right?

You might use "0hello" to send "Hello", for example.
And "4hello" to send "hellO"
 
0
 

Author Comment

by:Troudeloup
ID: 20386730
I want a function to output case correct strings on notepad give this

correctstring ("HeLLo")


and this doesn't pop up

hello


instead,

the intuitively expected

HeLLo

does.


makes sense?
0
 
LVL 13

Expert Comment

by:josgood
ID: 20386746
Yes, it does.  I'm trying a small test program now.  Having a couple of difficulties with it.  Stay tuned...
0
 
LVL 13

Expert Comment

by:josgood
ID: 20386782
I have some progress.  This small program sends a capital Q to the window that has focus.  

Unfortunately, it leaves the Caps Lock on...I'm looking into that

#include <windows.h>

   void SendShiftedChar(char aChar) {
      BYTE aByte = (BYTE)aChar;
     
      keybd_event( VK_CAPITAL ,0x45,KEYEVENTF_EXTENDEDKEY | 0, 0 );      
      keybd_event( aByte, 0, 0, 0 );
      keybd_event( aByte, 0, KEYEVENTF_KEYUP, 0);
      keybd_event( VK_CAPITAL, 0x45,KEYEVENTF_EXTENDEDKEY, 0 );      
      }
   
   void main() {
      ::Sleep(5000);  // Gives time to click Notepad
      SendShiftedChar( 'Q' );
   }
0
 
LVL 13

Expert Comment

by:josgood
ID: 20386800
OK, this sends a capital H.
#include <windows.h>

   void CapsLock() {
      keybd_event( VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );      
      keybd_event( VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0 );      
   }

   void SendChar(char aChar) {
      BYTE aByte = (BYTE)aChar;
      keybd_event( aByte, 0, 0, 0 );
      keybd_event( aByte, 0, KEYEVENTF_KEYUP, 0);
   }
   
   void SendShiftedChar(char aChar) {
      CapsLock();
      SendChar(aChar);
      CapsLock();
      }
   
   void main() {
      ::Sleep(3000);  // Gives time to click Notepad
      SendShiftedChar( 'H' );
   }
0
 
LVL 13

Accepted Solution

by:
josgood earned 2000 total points
ID: 20386810
This sends upper and lower case h.  You should be able to apply the same sort of logic as in SendChar for handling other keys.  The 0x20 magic number is the difference in hex between 'a' and 'A'.

'A' = 0x61, 'a' = 0x41

#include <windows.h>
#include <string>

   void CapsLock() {
      keybd_event( VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );      
      keybd_event( VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0 );      
   }

   void Send(char aChar) {
      keybd_event( aChar, 0, 0, 0 );
      keybd_event( aChar, 0, KEYEVENTF_KEYUP, 0);
   }
   
   void SendShiftedChar(char aChar) {
      CapsLock();
      Send(aChar);
      CapsLock();
      }
   
   void SendOneChar(char aChar) {
      if (aChar >= 'a' && aChar <= 'z') Send(aChar-0x20);
      else SendShiftedChar(aChar);
   }
   
   void main() {
      ::Sleep(3000);  // Gives time to click Notepad
     
      SendOneChar( 'h' );
      SendOneChar( 'H' );
   }
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

719 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