Solved

KeyBd_Event broken for multiple control keys in 64 bit systems

Posted on 2014-03-12
6
944 Views
Last Modified: 2014-03-31
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
Comment
Question by:GHG-RCH
  • 3
  • 2
6 Comments
 
LVL 53

Accepted Solution

by:
Joe Winograd, EE MVE earned 500 total points
ID: 39923783
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
 

Author Comment

by:GHG-RCH
ID: 39925906
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
 

Author Closing Comment

by:GHG-RCH
ID: 39925907
Marked as good as it suggested a way round without actually addressing the problem.
0
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 
LVL 53

Expert Comment

by:Joe Winograd, EE MVE
ID: 39926464
Interesting catch on the NumLock issue! Thanks for posting that. Regards, Joe
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39964734
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
 

Author Comment

by:GHG-RCH
ID: 39966046
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

733 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