[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

KeyBd_Event broken for multiple control keys in 64 bit systems

Posted on 2014-03-12
6
Medium Priority
?
1,028 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 56

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 56

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Assume you have an outside contractor who comes in seasonally or once a week to do some work in your office, but you only want to give him access to the programs and files he needs and keep all other documents and programs private. Can you do this o…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
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…

656 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