?
Solved

KeyBd_Event broken for multiple control keys in 64 bit systems

Posted on 2014-03-12
6
Medium Priority
?
996 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
[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
  • 3
  • 2
6 Comments
 
LVL 55

Accepted Solution

by:
Joe Winograd, EE MVE 2015&2016 earned 1500 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 55

Expert Comment

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

Expert Comment

by:Dale Fye
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Suggested Courses

801 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