Question

When keybrd_event and SendMessage(WM_KEYDOWN don't work???

Asked by: rpmccormi77

I am trying to control Google Earth.  I would like to use SendMessage(handle, WM_KEYDOWN, VK_?, 0) to control it without having to set focus using BringWindowToTop(handle), but for some reason it only works if it is on top.  The real problem is that I can't get it to accept a Shift-?.  I can press CTRL/ALT key combinations, but it when I do VK_SHIFT then VK_UP, it just interperates it as an up, not shift-up.  If I hold shift on my keyboard while it sends up it does a shift-up.  I have tried using WM_SYSKEYDOWN, VK_LSHIFT, VK_RSHIFT, and even keybrd_event(), but they all have the same problem.  What is going on here?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-02-14 at 21:01:46ID21737163
Tags

wm_keydown

,

sendmessage

Topic

Delphi Programming

Participating Experts
2
Points
50
Comments
16

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. SendMessage WM_LBUTTONDOWN to another window
    Hello, i want to send a message to another window(program - which i know only it's name - i don't have it's hwnd) this is the code i wrote: SendMessage((long)HWND_BROADCAST,WM_LBUTTONDOWN); Sleep(3000); SendMessage((long)HWND_BROADCAST,WM_LBUTTONUP); like u see - i want ...
  2. SendMessage
    I need to programmatically send keystrokes. For visible characters I use SendMessage(Screen.ActiveForm.ActiveControl.Handle, WM_CHAR, ord(''), 0) and this works fine. This also works for some nonvisible like backspace. The problem I have is with keys like Tab and Function ...
  3. SendMessage
    I have been trying to emulate the following two messages (captured from Spy++) for awhile now with SendMessage and SendMessageByString. I'm not sure with lparam and wparam are, so I haven't been able to get it to work right - any help would be appreciated. <00038> 0063...
  4. Help with Sendmessage
    Hello Experts, Have you ever used WM_KEYDOWN and VK_Key to enter text? I'm trying to use this code: =Module= Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public ...
  5. SendMessage with WM_MOVE
    Hi, I have a windowhandle "hwnd" and i want to move that window to a specified location. Can i use SendMessage function with WM_MOVE...?? If yes wht will be the fourth parameter...???? ie., SendMessge(hwnd, WM_MOVE, 0, ??????); How can i specify the desi...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: robert_marquardtPosted on 2006-02-14 at 22:47:49ID: 15958152

Show some code.

 

by: BigRatPosted on 2006-02-15 at 04:02:30ID: 15959424

>>but for some reason it only works if it is on top

Strictly speaking these messages can only be send/processed when the control has focus. Most programs don't bother to check (like me), but some do. Do a SetFocus(hWnd) before sending anything.

Secondly to simulate input the *correct* way is to use the SendInput() procedure which actually sets the input through the keyboard driver/buffer system. I suspect that the GetKeyState() function is NOT returning the shift status and so not seeing Shift+Up.

See Simulating Input at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/aboutkeyboardinput.asp

HTH

 

by: rpmccormi77Posted on 2006-02-15 at 11:40:06ID: 15963921

I have never seen any code using SendInput.  Could you post some?  I will look into it anyway.  keybrd_event is the old version though and it did not work.  FYI:  SetFocus() does not work, only BringWindowToTop() works.

Here my code as requested:

var
  Handle: hWND;
 begin
  Handle := Windows.GetWindow(Nil, 'Google Earth');
  Windows.BringWindowToTop(Handle);
  Windows.SendMessage(Handle, WM_KEYDOWN, VK_SHIFT, 0);
  Windows.SendMessage(Handle, WM_KEYDOWN, VK_LEFT, 0);
  Sleep(1000);
  Windows.SendMessage(Handle, WM_KEYUP, VK_LEFT, 0);
  Windows.SendMessage(Handle, WM_KEYUP, VK_SHIFT, 0);
 end;

The above code simulates LEFT, not Shift-LEFT?  If I change VK_SHIFT to VK_CONTROL, it does CTRL-LEFT fine.  I have tried using WM_SYSKEYUP/DOWN for the VK_SHIFT with no luck.  I have also tried using keybrd_event(VK_SHIFT,0,0,0) with no luck.

 

by: rpmccormi77Posted on 2006-02-15 at 11:59:35ID: 15964152

I found this SendInput code.  It didn't work at all.  It doesn't even send UP.

procedure TForm1.Button1Click(Sender: TObject);
var
  KeyInputs: array of TInput;
  KeyInputCount: Integer;

  procedure KeybdInput(VKey: Byte; Flags: DWORD);
   begin
    Inc(KeyInputCount);
    SetLength(KeyInputs, KeyInputCount);
    KeyInputs[KeyInputCount - 1].Itype := INPUT_KEYBOARD;
    with  KeyInputs[KeyInputCount - 1].ki do
     begin
      wVk := VKey;
      wScan := MapVirtualKey(wVk, 0);
      dwFlags := KEYEVENTF_EXTENDEDKEY;
      dwFlags := Flags or dwFlags;
      time := 0;
      dwExtraInfo := 0;
     end;
   end;
 begin
  Windows.BringWindowToTop(FindWindow(Nil, 'Google Earth'));
  KeybdInput(VK_SHIFT, 0);
  KeybdInput(VK_UP, 0);
  Sleep(1000);
  KeybdInput(VK_UP, KEYEVENTF_KEYUP);
  KeybdInput(VK_SHIFT, KEYEVENTF_KEYUP);
  SendInput(KeyInputCount, KeyInputs[0], SizeOf(KeyInputs[0]));
 end;

 

by: rpmccormi77Posted on 2006-02-15 at 21:51:05ID: 15968388

Ok, here is my latest code using SendInput:

[code]
procedure TForm1.Button1Click(Sender: TObject);
var
  intGEHandle, intOldHandle: hWND;
  GInput: array [0..0] of tagINPUT; //GENERALINPUT;
  // doesn't have to be array :)
 begin
  intOldHandle := GetForegroundWindow;
  intGEHandle := FindWindow(Nil, 'Google Earth');
  SetForegroundWindow(intGEHandle);

  GInput[0].Itype          := INPUT_KEYBOARD;
  GInput[0].ki.wVk         := VK_RSHIFT;
  GInput[0].ki.wScan       := 0;
  GInput[0].ki.dwFlags     := 0;
  GInput[0].ki.time        := 0;
  GInput[0].ki.dwExtraInfo := 0;
  SendInput(1, GInput[0], SizeOf(GInput));

  GInput[0].Itype          := INPUT_KEYBOARD;
  GInput[0].ki.wVk         := VK_LEFT;
  GInput[0].ki.wScan       := 0;
  GInput[0].ki.dwFlags     := 0;
  GInput[0].ki.time        := 0;
  GInput[0].ki.dwExtraInfo := 0;
  SendInput(1, GInput[0], SizeOf(GInput));

  Sleep(1000);

  GInput[0].Itype          := INPUT_KEYBOARD;
  GInput[0].ki.wVk         := VK_LEFT;
  GInput[0].ki.wScan       := 0;
  GInput[0].ki.dwFlags     := KEYEVENTF_KEYUP;
  GInput[0].ki.time        := 0;
  GInput[0].ki.dwExtraInfo := 0;
  SendInput(1, GInput[0], SizeOf(GInput));

  GInput[0].Itype          := INPUT_KEYBOARD;
  GInput[0].ki.wVk         := VK_RSHIFT;
  GInput[0].ki.wScan       := 0;
  GInput[0].ki.dwFlags     := KEYEVENTF_KEYUP;
  GInput[0].ki.time        := 0;
  GInput[0].ki.dwExtraInfo := 0;
  SendInput(1, GInput[0], SizeOf(GInput));

  SetForegroundWindow(intOldHandle);
 end;
[/code]




This actually does send RSHIFT-LEFT for 1000ms as it should.  It still has a bug though...  the RSHIFT is not released down.  If I return to Google Earth and press the arrow keys it acts as if shift is down.  If I press & release my left-shift button it does not fix it.  If I press & release my right shift button it does fix it.

I don't think RSHIFT-LEFT worked with the SendMessage() technique, but the keybrd_event and SendInput methods both work sending RSHIFT, they just won't release it.  using VK_SHIFT or VK_LSHIFT does not work with any method.

What is going on here?

 

by: rpmccormi77Posted on 2006-02-15 at 22:14:05ID: 15968457

Note:  I just tested the code out on note-pad.  I found out that it has the exact same problem, so it is not just Google Earth.  I also found out that the problem does not exist with SHIFT+[letter] combinations, it only exists with SHIFT+[arrow-key] combinations.

Hasn't anybody encountered this problem before?  What is the work-around?

 

by: rpmccormi77Posted on 2006-02-15 at 22:56:17ID: 15968639

Another follow up:

If I add the KEYEVENTF_EXTENDEDKEY:
    GInput.ki.dwFlags   := KEYEVENTF_EXTENDEDKEY
...then VK_SHIFT and VK_LSHIFT work just like VK_RSHIFT (that is the press but dont release).  Wait, it gets even stranger...

So, I can virtually-press shift using VK_RSHIFT with or without the flag, or by using VK_SHIFT or VK_LSHIFT but it has to be with the flag.  Then, if I virtually-release the shift using:
    GInput.ki.dwFlags   := KEYEVENTF_KEYUP or KEYEVENTF_EXTENDEDKEY
...the the left-shift key gets stuck down (I have to press the left-shift on my keyboard to restore normality).  If I don't use the flag like this:
    GInput.ki.dwFlags   := KEYEVENTF_KEYUP
...then it is the right-shift key that gets stuck down.

What the heck is going on here?

 

by: robert_marquardtPosted on 2006-02-15 at 23:03:18ID: 15968668

For arrow keys you may have to add the KEYEVENTF_EXTENDEDKEY flag. That flag distinguishes between numpad arrow keys and separate arrow keys.
Also set the wScan element aka second parameter of keybd_event. The documentation telling that it can be set to 0 is wrong.
To convert virtual keycode <-> scancode use MapVirtualKey.

 

by: rpmccormi77Posted on 2006-02-15 at 23:04:18ID: 15968674

SOLUTION:  Posting above gave me an idea...  do both!

This is a totally lame solution, but unless I find any other "special-cases" like the Shift+Arrow case, it works.

[code]
procedure TForm1.Button1Click(Sender: TObject);
var
  intGEHandle, intOldHandle: hWND;
 begin
  intOldHandle := GetForegroundWindow;
  intGEHandle := FindWindow('QWidget', 'Google Earth');
  SetForegroundWindow(intGEHandle);

  SimulateKeyDown(VK_SHIFT);
  SimulateKeyDown(VK_LEFT);
  Sleep(1000);
  SimulateKeyUp(VK_LEFT);
  SimulateKeyUp(VK_SHIFT);

  SetForegroundWindow(intOldHandle);
 end;

procedure SimulateKeyDown(MyKey: Cardinal);
var
  MyInput: tagINPUT;
 begin
  MyInput.Itype          := INPUT_KEYBOARD;
  MyInput.ki.wVk         := MyKey;
  MyInput.ki.wScan       := MapVirtualKey(MyKey, 0);
  if (MyKey = VK_SHIFT) then
    MyInput.ki.dwFlags   := KEYEVENTF_EXTENDEDKEY
  else
    MyInput.ki.dwFlags   := 0;
  MyInput.ki.time        := 0;
  MyInput.ki.dwExtraInfo := 0;
  SendInput(1, MyInput, SizeOf(MyInput));
 end;

procedure SimulateKeyUp(MyKey: Cardinal);
var
  MyInput: tagINPUT;
 begin
  MyInput.Itype          := INPUT_KEYBOARD;
  MyInput.ki.wVk         := MyKey;
  MyInput.ki.wScan       := MapVirtualKey(MyKey, 0);
  MyInput.ki.dwFlags     := KEYEVENTF_KEYUP;
  MyInput.ki.time        := 0;
  MyInput.ki.dwExtraInfo := 0;
  SendInput(1, MyInput, SizeOf(MyInput));

  if (MyKey = VK_SHIFT) then
   begin
    MyInput.ki.dwFlags     := KEYEVENTF_KEYUP or KEYEVENTF_EXTENDEDKEY;
    SendInput(1, MyInput, SizeOf(MyInput));
   end;
 end;
[/code]



I'm still interested in knowing why I have to use "KEYEVENTF_EXTENDEDKEY" for [Shift]+[Arrow] combinations, and why I have to send both "KEYEVENTF_KEYUP" and "KEYEVENTF_KEYUP or KEYEVENTF_EXTENDEDKEY" to get an extended [Shift] to release.  Points will be awarded for anything that will make my code cleaner or a list of other "special cases" and their work arounds.

 

by: robert_marquardtPosted on 2006-02-16 at 01:28:11ID: 15969338

You send Shift  Down with KEYEVENTF_EXTENDEDKEY so logically you have to send the Shift Up with the same Flag.
KEYEVENTF_EXTENDEDKEY distinguishes between left and right keys.
So it is logical that the OS gets confused if it gets left Shift down and right Shift up.

 

by: BigRatPosted on 2006-02-16 at 04:45:05ID: 15970520

Sorry I had to go away yesterday afternoon. It seems like we've done quite a lot. I would however like to mention a Tip at Torry's for this :-

http://www.swissdelphicenter.ch/torry/showcode.php?id=220

 

by: rpmccormi77Posted on 2006-02-16 at 10:53:37ID: 15973832

Thanks for the replies...

I tried all of the functions on that Torry page before, but none of them would sucessfully send a Shift+Arrows (again, CTRL-Arrow, ALT-Arrow, and Shift-Letter all work fine using all methods I have tried, it is just a Shift+Arrow problem).

Even if I use the KEYEVENTF_EXTENDEDKEY with VK_LSHIFT or VK_RSHIFT, I still have to send a WM_KEYUP both with and without the KEYEVENTF_EXTENDEDKEY flag in order for the key to actually be released.  Why?

It seems that all if these:
1) GInput[0].ki.wVk         := VK_RSHIFT;
    GInput[0].ki.dwFlags     := 0;
2) GInput[0].ki.wVk         := VK_RSHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_EXTENDEDKEY;
3) GInput[0].ki.wVk         := VK_LSHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_EXTENDEDKEY;
4) GInput[0].ki.wVk         := VK_SHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_EXTENDEDKEY;
but BOTH shift buttons down.

All of these raise the left shift button:
1) GInput[0].ki.wVk         := VK_RSHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_KEYUP;
2) GInput[0].ki.wVk         := VK_LSHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_KEYUP;
3) GInput[0].ki.wVk         := VK_SHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_KEYUP;

All of these raise the right shift button:
1) GInput[0].ki.wVk         := VK_RSHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_KEYUP;
2) GInput[0].ki.wVk         := VK_LSHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_KEYUP;
3) GInput[0].ki.wVk         := VK_SHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_KEYUP;

All of these raise the left shift button:
1) GInput[0].ki.wVk         := VK_RSHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_KEYUP or KEYEVENTF_EXTENDEDKEY;
2) GInput[0].ki.wVk         := VK_LSHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_KEYUP or KEYEVENTF_EXTENDEDKEY;
3) GInput[0].ki.wVk         := VK_SHIFT;
    GInput[0].ki.dwFlags     := KEYEVENTF_KEYUP or KEYEVENTF_EXTENDEDKEY;

And these don't do anything:
1) GInput[0].ki.wVk         := VK_SHIFT;
    GInput[0].ki.dwFlags     := 0;
2) GInput[0].ki.wVk         := VK_LSHIFT;
    GInput[0].ki.dwFlags     := 0;

Why?

Also, I tried plaing around with ThreadID stuff and got it to work sending keys to my program after binding the thread inputs, but the Shift+Arrow thing still didn't work (and GE still needed focus to recieve the keys, so it is no better than SendInput).  My only working solution is by using SendInput and KEYEVENTF_EXTENDEDKEY, but this requires me to use 2 SendInputs to release the shift key (one with and and without the KEYEVENTF_EXTENDEDKEY).

I still have not seen any code that can send even VK_LEFT alone to GoogleEarth without it having focus (not a requirement, but it would be nice).

 

by: rpmccormi77Posted on 2006-02-16 at 10:55:49ID: 15973872

I hate how you can not edit or preview your posts on this site :(

of
put
ignore the second list-group

 

by: BigRatPosted on 2006-02-17 at 05:43:35ID: 15980420

There are two things I don't understand.

1) Why is the flag KEYEVENTF_EXTENDEDKEY set? (*see below)
2) Why in SimulateKeyUp SendInput is done twice on VK_SHIFT?

The old way with keybd_event is deprecated, one should use SendInput, but there are plenty of examples on the web where the sequence is performed which are equivalent to SendInput, eg:

http://www.delphipages.com/tips/thread.cfm?ID=78
http://delphi.about.com/od/adptips2004/a/bltip0604_4.htm
 
even in VB

http://www.experts-exchange.com/Programming/Q_20879518.html


* This site implements a C++ class for this and defines the Extended keys :-

http://cvs.sourceforge.net/viewcvs.py/keepass/keepass/Util/SendKeys.cpp?rev=1.3

 

by: rpmccormi77Posted on 2006-02-17 at 11:30:04ID: 15983616

Thanks for your comments.  First let me answer your questions:

1) Otherwise Shift+Left only sends Left.
2) Otherwise either the Left-Shift or Right-Shift is not released.  For some reason using KEYEVENTF_EXTENDEDKEY holds both Shift buttons, but it will only release one button (and not using it will release the other), therefore I have to do SendInput twice (once with the flag and once without).

Do the above answers make any logical since: No, but it is how I know it to work via much experimentation.

Now, your first two posts are things I have seen before and I don't find helpful.  However, the third post lists the "extended keys" which is very interesting.

    VK_UP,
    VK_DOWN,
    VK_LEFT,
    VK_RIGHT,
    VK_HOME,
    VK_END,
    VK_PRIOR, // PgUp
    VK_NEXT,  //  PgDn
    VK_INSERT,
    VK_DELETE

According to this list, shift is not an extended key, but the direction arrows all are.  Since I could always send LEFT and just had trouble sending Shift-LEFT, I assumed shift was the problem.  Let me try not setting shift as an extended key, but setting LEFT as an extended key instead.  Hopfully that will successfully send Shift-Left, and allow both to be released with one SendInput command for each (instead of needing two just to release shift).  I'll give it a try.

 

by: rpmccormi77Posted on 2006-02-17 at 14:09:59ID: 15985354

That worked!  Yay!

Here's my functions now:

[code]
procedure SimulateKeyDown(MyKey: Cardinal);
var
  MyInput: tagINPUT;
 begin
  MyInput.Itype          := INPUT_KEYBOARD;
  MyInput.ki.wVk         := MyKey;
  MyInput.ki.wScan       := MapVirtualKey(MyKey, 0);

  if (MyKey = VK_UP)
  or (MyKey = VK_DOWN)
  or (MyKey = VK_LEFT)
  or (MyKey = VK_RIGHT)
  or (MyKey = VK_HOME)
  or (MyKey = VK_END)
  or (MyKey = VK_PRIOR)
  or (MyKey = VK_NEXT)
  or (MyKey = VK_INSERT)
  or (MyKey = VK_DELETE) then
    MyInput.ki.dwFlags   := KEYEVENTF_EXTENDEDKEY
  else
    MyInput.ki.dwFlags   := 0;
  MyInput.ki.time        := 0;
  MyInput.ki.dwExtraInfo := 0;

  SendInput(1, MyInput, SizeOf(MyInput));
 end;

procedure SimulateKeyUp(MyKey: Cardinal);
var
  MyInput: tagINPUT;
 begin
  MyInput.Itype          := INPUT_KEYBOARD;
  MyInput.ki.wVk         := MyKey;
  MyInput.ki.wScan       := MapVirtualKey(MyKey, 0);

  if (MyKey = VK_UP)
  or (MyKey = VK_DOWN)
  or (MyKey = VK_LEFT)
  or (MyKey = VK_RIGHT)
  or (MyKey = VK_HOME)
  or (MyKey = VK_END)
  or (MyKey = VK_PRIOR)
  or (MyKey = VK_NEXT)
  or (MyKey = VK_INSERT)
  or (MyKey = VK_DELETE) then
    MyInput.ki.dwFlags   := KEYEVENTF_KEYUP or KEYEVENTF_EXTENDEDKEY
  else
    MyInput.ki.dwFlags     := KEYEVENTF_KEYUP;

  MyInput.ki.time        := 0;
  MyInput.ki.dwExtraInfo := 0;

  SendInput(1, MyInput, SizeOf(MyInput));
 end;
[/code]

Ok, I'm awarding points for the list of actual extended keys ;)

I do have one more question though: There seems to be no VK_[code] for the equals key ("=").  Is VK_OEM_PLUS actually "=" and only "+" when shift is held?

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...