Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:31:13+00:00 2026-06-07T04:31:13+00:00

I would like to simulate shortcuts for a remote control feature of our Windows

  • 0

I would like to simulate shortcuts for a remote control feature of our Windows Mobile application. Any possible shortcut should be supported (think of Ctrl+/ or Alt+ä).

With keybd_event I can simulate shortcuts very well, but only Virtual-Key Codes are allowed with this function. Therefore, I thought of the PostKeybdMessage function which allows me to send any character to the foreground window. But if I combine the two calls, Windows will just print the character instead of executing the shortcut.

Here’s what I tried:

  • Sending the CTRL key silently (KEYEVENTF_SILENT)
  • Adding the KeyShiftAnyCtrlFlag to the PostKeybdMessage call
  • Played a lot with the buffers and the flags of the PostKeybdMessage call (which is quite confusing)

My questions are:

  • Can PostKeybdMessage be used to simulate shortcuts or am I just wasting my time? If it can, what did I do wrong in the code sample?
  • Is there maybe a trick to send special characters (umlauts, #, =, …) with keybd_event?
  • Is there another way to simulate a shortcut?

Simple test application

public partial class ShortcutTest : Form
{
  private const int KEYEVENTF_KEYUP = 0x0002;
  private const int HWND_FOREGROUND = -1;

  private const uint KEY_STATE_DOWN = 0x0080;
  private const uint KEY_SHIFT_NO_CHARACTER = 0x00010000;
  private const uint KEY_SHIFT_ANY_CONTROL = 0x40000000;

  private const byte VK_CONTROL = 0x11; // Keys.ControlKey

  [DllImport("coredll.dll", SetLastError = true)]
  internal static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

  [DllImport("coredll.dll")]
  private static extern bool PostKeybdMessage(int hwnd, uint vKey, uint KeyStateFlags, uint cCharacters, uint[] pShiftStateBuffer, uint[] pCharacterBuffer);

  public ShortcutTest()
  {
    InitializeComponent();
  }

  private void timer1_Tick(object sender, EventArgs e)
  {
    timer1.Enabled = false;

    keybd_event((byte)Keys.ControlKey, 0, 0, 0);

    // this would work: keybd_event((byte)Keys.X, 0, 0, 0);

    // this won't work
    SendChar('x');

    //keybd_event((byte)Keys.X, 0, KEYEVENTF_KEYUP, 0);

    keybd_event((byte)Keys.ControlKey, 0, KEYEVENTF_KEYUP, 0);

    button1.Enabled = true;
  }

  private void button1_Click(object sender, EventArgs e)
  {
    timer1.Enabled = true;
    button1.Enabled = false;
  }

  public void SendChar(char ch)
  {
    uint[] input = new uint[] { (uint)ch };

    uint[] downStates = { KEY_STATE_DOWN | KEY_SHIFT_ANY_CONTROL };
    uint[] upStates = { KEY_SHIFT_NO_CHARACTER | KEY_SHIFT_ANY_CONTROL };

    PostKeybdMessage(HWND_FOREGROUND, 0, downStates[0], 1, downStates, input);

    // tested with KeyShiftDeadFlag and some others, with \0 char ...
    PostKeybdMessage(HWND_FOREGROUND, 0, upStates[0], 1, upStates, input);
  }

}

Edit: I just looked up the OpenNETCF implementation of SendKeys and they use keybd_event only (so “+a” will fail for example).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:31:15+00:00Added an answer on June 7, 2026 at 4:31 am

    Have you tried using SendInput? I am actually using c++, and following code:

    INPUT input[4];
    memset(input, 0, sizeof(INPUT)*4);
    input[0].type = INPUT_KEYBOARD;
    input[0].ki.wVk = VK_MENU;
    
    input[1].type = INPUT_KEYBOARD;
    input[1].ki.wVk = L'a';
    
    input[2].type = INPUT_KEYBOARD;
    input[2].ki.wVk = VK_MENU;
    input[2].ki.dwFlags = KEYEVENTF_KEYUP;
    
    input[3].type = INPUT_KEYBOARD;
    input[3].ki.wVk = L'a';
    input[3].ki.dwFlags = KEYEVENTF_KEYUP;
    
    SendInput(4, input, sizeof(INPUT));
    

    generates messages that look like should work, I checked in spy on WM6.5.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know what exactly this feature is, but I would like to simulate
I would like to simulate a call in an iPhone app. Is it possible
I am developing a Flex application in which I would like to simulate roughly
I would like to end a certain Windows application gracefully, without using a mouse
We would like to simulate Imagemagick functionality, but only in Javascript. Do any libraries
I would like to know if it's possible to simulate the process: Right click
I would like to simulate that my ASP.NET application is hist by say simdomain.com.
I would like to simulate the user pressing tab then enter when they press
I am rendering textured quads from an orthographic perspective and would like to simulate
Would like to know what a programmer should know to become a good at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.