Click here to Skip to main content
16,008,010 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralWaitCommEvent Pin
Sergei15-Dec-01 13:19
Sergei15-Dec-01 13:19 
GeneralSending Keystrokes to another process Pin
#realJSOP15-Dec-01 9:00
professional#realJSOP15-Dec-01 9:00 
GeneralRe: Sending Keystrokes to another process Pin
Michael Dunn15-Dec-01 10:55
sitebuilderMichael Dunn15-Dec-01 10:55 
GeneralRe: Sending Keystrokes to another process Pin
Daniel Ferguson15-Dec-01 12:05
Daniel Ferguson15-Dec-01 12:05 
GeneralRe: Sending Keystrokes to another process Pin
Tim Smith15-Dec-01 16:03
Tim Smith15-Dec-01 16:03 
GeneralRe: Sending Keystrokes to another process Pin
Tim Deveaux15-Dec-01 18:05
Tim Deveaux15-Dec-01 18:05 
GeneralRe: Sending Keystrokes to another process Pin
Mustafa Demirhan16-Dec-01 17:03
Mustafa Demirhan16-Dec-01 17:03 
GeneralRe: Sending Keystrokes to another process Pin
Tim Deveaux15-Dec-01 14:24
Tim Deveaux15-Dec-01 14:24 
Got caught up in this. Yep, I think PostMessage helps (as you may have already seen), and setting the proper transition flag - on for WM_KEYUP. I think you already have the repeat count right.

The ugly processor hogging code below also borrows from the sample mentioned to get the scan code and stuff, but I don't think the scan is needed.

This code doesn't check the alt, shift, ctrl keys etc, but I assume it could send things like Alt+F4 if it did. Could be one for the FAQ with a bit of work. - 'Write a SendKeys(HWND, LPCTSTR) function...'

Note the elegant hardcoding of the hwnd (er... Calculator Blush | :O )

// Console.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "crtdbg.h"
#include "conio.h"
#include "windows.h"
#include "winbase.h"
 
 
int main(int argc, char* argv[])
{
    HWND    hwnd = (HWND)  0x025c;
     
    INT Vk;
    INT Scan;
    CHAR character[2];
    CHAR oemchar[2];
    CHAR ch;
    do {
        while(!_kbhit());
        ch = getch();
        
        character[0]=ch;
        character[1]='\0';
        
        // Get the virtual key code for this character
        Vk = VkKeyScan(character[0]) & 0xFF;  
        CharToOem(character, oemchar);
        
        // Get the scan code for this key
        Scan = OemKeyScan(oemchar[0]) & 0xFF;
        
        // show the key:
        printf("Key = %c, VK code = %d, scan = %d\n", ch, Vk, Scan);
        
        UINT    lKeydata = 0;
 
        UINT    mask = 1;
        lKeydata |= mask;         // repeat count of 1;
        lKeydata |= Scan << 15;   // not really necessary for most apps
         
        ::PostMessage(hwnd, WM_KEYDOWN, Vk, lKeydata);
         
        lKeydata |= mask;         // repeat count of 1;
        lKeydata |= Scan << 15;
        lKeydata |= mask << 31;   // transition (fUp) is 1 for key up.
         
        ::PostMessage(hwnd, WM_KEYUP, Vk, lKeydata);
    }
    while(1);
    return 0;
}

GeneralRe: Sending Keystrokes to another process Pin
#realJSOP16-Dec-01 3:15
professional#realJSOP16-Dec-01 3:15 
GeneralRe: Sending Keystrokes to another process Pin
Tim Deveaux16-Dec-01 4:00
Tim Deveaux16-Dec-01 4:00 
GeneralPrinting Problem! Pin
Mazdak15-Dec-01 8:36
Mazdak15-Dec-01 8:36 
GeneralBeyond Fundamental C++ - Experience Pin
valikac15-Dec-01 7:03
valikac15-Dec-01 7:03 
GeneralRe: Beyond Fundamental C++ - Experience Pin
Tim Smith15-Dec-01 8:00
Tim Smith15-Dec-01 8:00 
GeneralRe: Beyond Fundamental C++ - Experience Pin
Michael Dunn15-Dec-01 8:39
sitebuilderMichael Dunn15-Dec-01 8:39 
GeneralRe: Beyond Fundamental C++ - Experience Pin
valikac15-Dec-01 9:31
valikac15-Dec-01 9:31 
GeneralRe: Beyond Fundamental C++ - Experience Pin
valikac15-Dec-01 10:13
valikac15-Dec-01 10:13 
GeneralRe: Beyond Fundamental C++ - Experience Pin
Tim Smith15-Dec-01 10:27
Tim Smith15-Dec-01 10:27 
GeneralRe: Beyond Fundamental C++ - Experience Pin
valikac15-Dec-01 10:51
valikac15-Dec-01 10:51 
GeneralRe: Beyond Fundamental C++ - Experience Pin
Todd Smith16-Dec-01 5:00
Todd Smith16-Dec-01 5:00 
GeneralRe: Beyond Fundamental C++ - Experience Pin
valikac16-Dec-01 5:20
valikac16-Dec-01 5:20 
GeneralFunction explored from .exe files and heap problems Pin
Marc Richarme15-Dec-01 6:02
Marc Richarme15-Dec-01 6:02 
GeneralRe: Function explored from .exe files and heap problems Pin
Igor Sukhov15-Dec-01 6:14
Igor Sukhov15-Dec-01 6:14 
GeneralRe: Function explored from .exe files and heap problems Pin
Marc Richarme15-Dec-01 8:47
Marc Richarme15-Dec-01 8:47 
GeneralRe: Function explored from .exe files and heap problems Pin
Joaquín M López Muñoz16-Dec-01 2:57
Joaquín M López Muñoz16-Dec-01 2:57 
QuestionHow to integrate a Button Object into the middle of the Mainframe at Runtime. Pin
Alexander_BMW15-Dec-01 5:20
Alexander_BMW15-Dec-01 5:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.