• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1080
  • Last Modified:

KeyBd_Event broken for multiple control keys in 64 bit systems

I have a longstanding application which sends keystrokes using KeyBd_Event in the User32 dll.

While it mostly works, where we send combinations like {Ctrl+Shift+Home} only the first control key (in the order Shift Ctrl Alt) is now recognised for 64 bit windows.

The code puts the required control keys down, then sends the characters required, then puts the control keys up again, all using KeyBd_Event calls.

This works fine in 32 bit XP & W7 but not in 64 bit W7.
I have not yet tested 32 bit W8 or 64 bit XP and W8).

If you are aware of a solution to this issue I would be grateful.
It looks as if when one control key is depressed other control keys are raised.

I am now looking at switching to SendInput for 64bit systems, but would obviously prefer to stay with code that has been working well for a long time.

It happens that I am coding in Delphi-7 but since I end up calling the API directly I don't think this is particularly relevant to the problem, though a solution in Delphi would be helpful, though any other language would be OK also.
0
GHG-RCH
Asked:
GHG-RCH
  • 3
  • 2
1 Solution
 
Joe Winograd, EE MVE 2015&2016DeveloperCommented:
If you're willing to consider a different product to send keystrokes, I've been using AutoHotkey (excellent and free!) with complete success in W7/64-bit (and W8/64-bit). There have been many forks of the original language and recently a new community was established to move the language forward. The latest release at the new community has a Windows installer, an offline help file, and a compiler that turns the AHK source code (plain text) into a stand-alone/no-install executable (an EXE file).

There is excellent documentation:
http://ahkscript.org/docs/AutoHotkey.htm

...including an alphabetical command and function index:
http://ahkscript.org/docs/commands/index.htm

...a good tutorial:
http://ahkscript.org/docs/Tutorial.htm

...and an active user forum:
http://ahkscript.org/boards/

I started out with AutoHotkey when my old keyboard macro program wouldn't work in W7/64-bit, but now I use it for more than just sending keystrokes, as it is a complete, robust programming/scripting language. If you'd like to see it used in a full program, here's an EE article that includes a description of all the AutoHotkey code snippets:
http://www.experts-exchange.com/Web_Development/Document_Imaging/A_10745-How-To-Combine-Merge-Append-TIFF-Files-in-Batch-Mode.html

Give AutoHotkey a spin — I think you'll like it. Regards, Joe
0
 
GHG-RCHAuthor Commented:
Since posting this question we have found that the problem is associated with NumLock.
If NumLock is active then this problem occurs.
I will modify the code to determine the NumLock state, set it off, do what is needed, then set it back on again.

I will also look at AutoHotKey, though we try to minimise the use of non source third party products because it can become quite complex keeping things up to date, support is sometimes unreliable and the long term existence of the product is not guaranteed.
0
 
GHG-RCHAuthor Commented:
Marked as good as it suggested a way round without actually addressing the problem.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Joe Winograd, EE MVE 2015&2016DeveloperCommented:
Interesting catch on the NumLock issue! Thanks for posting that. Regards, Joe
0
 
Dale FyeCommented:
GHG-RCH,

I'm looking to implement something similar but simply need to send the shift key to the keyboard prior to opening a database using automation.

Care to share:

How do you declare the user32.dll?

How do you then send the shift key to the keyboard?
0
 
GHG-RCHAuthor Commented:
I use it through the Delphi Windows unit.
I call the keybd_event function and send approprirate KeyDown and KeyUp calls.
This works fine normally, however if NumLock is on single control key calls work OK (e.g. Ctrl-C) but multiple control key events do not and the system acts as if only one has been pressed (e.g. Ctrl-Shift-Home is treated ad Ctrl-Home or Shift-Home).
I have worked round this problem by detecting NumLock, taking it off, carrying out the required operation, then putting it back to the previous state. Everything now works fine.
0

Featured Post

Meet the Family that is Made for Collaboration

The TeamConnect Family product group as part of the Sennheiser for Business Portfolio comprising high-quality, technically well-conceived meeting solutions for business communication – designed for any meeting room and any meeting situation.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now