?
Solved

Difficulty w/ SendKeys

Posted on 2000-03-25
12
Medium Priority
?
562 Views
Last Modified: 2012-05-04
I am writing an application to update a database on the mainframe.  I have no difficulty putting new names in, but in order to get to the next record, I need to press either the right control key or the enter key on the numeric pad.  I have tried SendKeys("^") and SendKeys("~") but have been unsuccessful.  I was thinking of maybe being able to use an ASCII code.  Any advice??
0
Comment
Question by:jpulford
[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
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2656890
SendKeys can not differentiate between the left and right control key or the enter on the numeric keypad and the enter on the main keyboard.  You will have to determine what the control sequence is and send it manually...
0
 

Expert Comment

by:tdtomlins
ID: 2656939
If your using VB controls and not your own made up ones use the KeyPress event I believe the Enter key is (Keycode 13) and the left control is (keycode 17 and shift 2) just add an If then Statement with a setfocus event to differentiant between the two.  Hope this is what you wanted just use the KEYPRESS EVENT for the control.  (Better yet make a call statemente in  the keypress event and call a user made Event that moves to the next control through the setfocus method
0
 

Author Comment

by:jpulford
ID: 2657117
Do you know what the key code for the right control key is?  I can offer more points for a bit of sample code.  Thanks.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Expert Comment

by:wsh2
ID: 2657138
This sounds like an IBM application interface.. Since, IBM only processes on frame boundaries.. pressing the Enter key sends a whole screen of data.. not an individual field as it does in PC land. As the Enter key in IBM Land is in effect a send key, IBM provided other keys (not used in PC Land) for field navigation. Many IBM/PC emulation programs map these special IBM navigational / Field formatting keys to the Control and / or Shift keys or any other key that has an equivalent to an IBM mainframe keyboard.

Certainly TdTomlins comment will work.. intercept the keypress event of every Control on the form and take the appropriate action from there. It is a pure VB solution, but a lot of work. However, as this is a keyboard problem more than a software one.. the best solution would be to use APIs and application Hook the Keyboard.. as is done in most emulation programs. But be advised, this an advanced programming concept, not for the faint of heart, or the novice. As I do not know the writer's ability, I will not go into that here. However, if the writer wants to know more about keyboard hooks he should post another question.. and I'm certain he will get ample consideration to his question.

Other thoughts that I had to a pure VB solution.. would be to setup a menu and use the shortcut key functionality imbibed within it. For example.. A Control+E if menu programmed would fire an easily trappable menu event, from which you could easily do your processing.

All in all, I personally do not like the idea of emulating the IBM mainframe keyboard. Giving a key a different unlabeled meaning can be very confusing for the novice keyboard operator, particularily one who has no mainframe experience. If you can, try and stay true to the platform you are working on (in this case the PC) and you will find that your application will be easier to program and in the long run prove much more worthy. Face it jpulford.. PCs are here to stay and sadly, the days of the dumb mainframe terminal are pretty much dead.. code to the platform.. you will be happy that you did.. <smile>.
0
 

Author Comment

by:jpulford
ID: 2657287
Thanks for all of your help.  There is just one last piece of info I would like to have before I dole out the points.  Does anyone know the key code for the right control key? I am going to up the ante 100 pts.  Game's On
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2657575
The only way I know to interrogate the Left / Right - Shift / Ctrl keys is by using the GetAsyncKeyState() or GetKeyState () APIs. With them, you would test for:

Const VK_LSHIFT = A0&
Const VK_RSHIFT = A1&
Const VK_LCONTROL = A2&
Const VK_RCONTROL = A3&

0
 
LVL 14

Expert Comment

by:mcrider
ID: 2657642
Like I said earlier, SendKeys can not differentiate between the left and right control key or the enter on the numeric keypad and the enter on the main keyboard.

Both the left and right control key generatess a keycode of 17 and both enter keys generate a keycode of 13.

What is happening is when you press the right control key in your emulator software is that a "Key Sequence" is being generated... Not a single keystroke.  You are going to have to determine what the key sequence is (either from the emulator documentation or by tracing the connection between the emulator and the mainframe.)

A "Key Sequence" is a series of characters that are sent to a mainframe when a specific key is pressed on the keyboard.  What sequence that is sent is determined by the "Keyboard Map". This map is specified by the protocol used to connect to the mainframe.

An example of a key sequence in the UNIX VT100 protocol is Inverse Video which is: ^[[7m
To turn of Inverse Video the key sequence is: ^[[0m

Where ^[ is the ESC key.


To repeat, when your emulator software is running and you press the right control key or the numeric enter key, a single keystroke is not being sent to the mainframe...



Cheers!®©
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2657693
Although jpulford has not expressly said it.. it really does sound like he is trying to interface with an IBM mainframe terminal emulator window. As these programs often implement their own keyboard hooks and remapping.. perhaps jpulford's emulator software has programming features that he could employ in a much easier fashion. Most emulator software packages provider technical documentation and APIs to allow the user to employ their interface.. <smile>. jpulford.. I would check your docs, and the emulator software website for more information.

As mcrider quite correctly comments, there is no native way in VB to get / put the information you require. That then leaves you 2 options.. Windows API programming enhancements or the emulator software's programming interface.. <smile>
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2657756
One more thing... You have not mentioned the emulator protocol, however, every emulator I have EVER played with will pass on the keystrokes that would be generated by pressing the mapped key... For example, lets say for the sake of this discussion that when you hit the "Shift F1" key in the emulator, it is actually mapped to send the key sequence: ESC [ 1 ;

If you where to hit those keys on the keyboard, you would be sending the "Shift F1"...


Cheers!®©
0
 
LVL 14

Accepted Solution

by:
mcrider earned 450 total points
ID: 2785342
jpulford, Just checking back... Did you get what you needed?? If so, Please accept an answer.


Cheers!®©
0
 

Expert Comment

by:tdtomlins
ID: 2785684
using the api GetKeyState () APIs works for distinguishing the left and right control key's but only within NT or 2000 environment.  all the 9?  will only detect that a control key was pressed but will not distinguish between left and right.

0
 
LVL 14

Expert Comment

by:mcrider
ID: 2786889
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 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