Sending Ctrl+letter to application using PostMesssage or SendMessage

This is a discussion on Sending Ctrl+letter to application using PostMesssage or SendMessage within the C# Programming forums, part of the General Programming Boards category; Hi! I've been trying to send Ctrl+s to notepad, but havent succesfully manage to do this. I've googled it, but ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    1

    Sending Ctrl+letter to application using PostMesssage or SendMessage

    Hi!

    I've been trying to send Ctrl+s to notepad, but havent succesfully manage to do this. I've googled it, but havent found anyone who have sent a ctrl+letter command to a process.

    Currently, the sending part of my code look like this:
    Code:
    IntPtr hWnd = FindWindow("Notepad", null); 
    IntPtr hWndChild = FindWindowEx(hWnd, IntPtr.Zero, "Edit", null); 
    int VK_CONTROL = (int)0x11;
    uint wm_keydown = (uint)0x100; 
    uint wm_char = (uint)0x102; 
    uint wm_keyup = (uint)0x101; 
     
    PostMessage(hWndChild, wm_keydown, VK_CONTROL, 0);       //Send Ctrl down 
    PostMessage(hWndChild, wm_keydown, VkKeyScan('s'), 0);   //Send 's' down 
    PostMessage(hWndChild, wm_keyup, VkKeyScan('s'), 0);     //Send 's' up 
    PostMessage(hWndChild, wm_keyup, VK_CONTROL, 0);         //Send Ctrl up
    I've also tried different values for the lParam parameter (taken from Spy++) and to use hWnd instead of hWndChild, but it does not work. Does anyone know any way to send Ctrl+s to notepad using PostMessage (or SendMessage)? I would really appreciate if anyone could post some sample code. Thank you!

  2. #2
    Registered User khdani's Avatar
    Join Date
    Oct 2007
    Posts
    42
    reoverload the PostMessage function
    Code:
            [return: MarshalAs(UnmanagedType.Bool)]
            [DllImport("user32.dll", SetLastError = true)]
            static extern bool PostMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr 
    lParam);
    and pass the LPARAM and WPARAM as IntPtr.
    use hWnd instead of the later, but i think the name of the window is not
    "Notepad" but "Filename - Notepad" and if it's new instance then it's "Untitled - Notepad"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I ...
    By geekrockergal in forum C Programming
    Replies: 21
    Last Post: 02-07-2009, 09:40 AM
  2. counting letter occurences in a string
    By pjr5043 in forum C++ Programming
    Replies: 35
    Last Post: 05-05-2008, 09:18 PM
  3. help using strings and mapping
    By trprince in forum C Programming
    Replies: 29
    Last Post: 12-01-2007, 03:01 PM
  4. Recognizing ALT or Ctrl + letter
    By MethodMan in forum C Programming
    Replies: 2
    Last Post: 02-22-2003, 06:16 PM
  5. Replies: 1
    Last Post: 06-06-2002, 04:17 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21