Link to home
Start Free TrialLog in
Avatar of jpulford
jpulford

asked on

Difficulty w/ SendKeys

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??
Avatar of mcrider
mcrider

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...
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
Avatar of jpulford

ASKER

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.
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>.
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
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&

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!®©
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>
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!®©
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

Thanks for the points! Glad I could help!


Cheers!®©