Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

To simulate a keystroke

Posted on 1999-07-23
3
Medium Priority
?
316 Views
Last Modified: 2013-12-03
How can I send for instance ALT + 'a' keystroke from a program? I didn't find any API except keybd_event() which does not have a way to specify the ALT key.

Platform: WINDOWS NT 4.0 and KeyboardEventEx() API is not available.
0
Comment
Question by:alex1234
[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
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
BudVVeezer earned 200 total points
ID: 1403585
The way that I send keys is this simple function that I wrote up.  It SHOULD work on NT, but don't hold me to that!  ;-)

void SendKeys(BYTE vk, BYTE ch, HWND wind)
{
      SetForegroundWindow(wind);
      
      keybd_event(vk, 0, 0, 0);
      keybd_event(ch, 0, 0, 0);
      keybd_event(ch, 0, KEYEVENTF_KEYUP, 0);
      keybd_event(vk, 0, KEYEVENTF_KEYUP, 0);
}

/******Use*****/
SendKeys(VK_ALT, 'a', hWnd);

What it does is set the window to the foreground so it can recieve keyboard input, then it sets the keyboard state of the first param to down.  Then it sets the second key.  Then it releases the second key, and then the first key.  Viola!  It should work for you.  I use it to send CTL messages to windows in Win95, it should work great for ALT messages too.  To get the hWnd of the window(if you don't already have it), use the FindWindow or FindWindowEx funtion.

~Aaron
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 1403586
>> it should work great for ALT messages too
not with VK_ALT (its not defined)!
use VK_MENU or 0x12 instead
0
 
LVL 3

Expert Comment

by:BudVVeezer
ID: 1403587
LoL, ok!  Thanks for the tip!  Like I said, I've only used it for CTL keys.  =)

~Aaron
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

661 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