views:

41

answers:

1

I'm working on a program that automates the use of this piece of software, EPIX XCAP.

In Capture(), it snaps a picture, opens up the File menu, open up the save dialog, but then with it reaches the Tabs (to navigate to the file name box in the save dialog) it doesn't do them. I can tab through it manually well enough, and I tested the Type(VK_TAB) loop in notepad and it worked fine there, so I have no idea why it won't work.

I initially tried to use SendInput as opposed to keybd_event, but i couldn't get it working with Ctrl/Alt, in case you're wondering.

Any and all help is much appreciated.

void Type(int x){
    const int KEYEVENT_KEYUP = 0x02;
    keybd_event(x,0,0,0);
    keybd_event(x,0,KEYEVENT_KEYUP,0);
}

void Ctrl(int x){  
    const int KEYEVENT_KEYUP = 0x02;
    keybd_event(VK_CONTROL,0,0,0);              // press the CTRL key
    keybd_event(x,0,0,0);
    keybd_event(x,0,KEYEVENT_KEYUP,0);
    keybd_event(VK_CONTROL,0,KEYEVENT_KEYUP,0); // let up the CTRL key
}

void Alt(int x){  
    const int KEYEVENT_KEYUP = 0x02;
    keybd_event(VK_MENU,0,0,0);              // press the ALT key
    keybd_event(x,0,0,0);
    keybd_event(x,0,KEYEVENT_KEYUP,0);
    keybd_event(VK_MENU,0,KEYEVENT_KEYUP,0); // let up the ALT key
}

void Shift(int x){  
    const int KEYEVENT_KEYUP = 0x02;
    keybd_event(VK_SHIFT,0,0,0);              // press the SHIFT key
    keybd_event(x,0,0,0);
    keybd_event(x,0,KEYEVENT_KEYUP,0);
    keybd_event(VK_SHIFT,0,KEYEVENT_KEYUP,0); // let up the SHIFT key
}

void Capture(string filename){
    Ctrl('S');
    Alt(VK_SPACE);
    Type(VK_RIGHT);
    Type(VK_RETURN);
    for(int a = 0; a < 13; a++){
        Type(VK_TAB);
    }
    for(int b = 0; b < filename.length(); b++){
        Type(filename[b]);
    }
    Type(VK_RETURN);
}
A: 

When you are sending keyboard events, don't you need to send the code that specifies which control was pressed? GetKeyState and GetAsyncKeyState are the APIs used to find out which keys are held down and they respond to VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL etc (in addition to the position independent VK_CONTROL, VK_SHIFT etc).

Chris Becke