VideoHelp Forum
+ Reply to Thread
Results 1 to 5 of 5
Thread
  1. Renegade gll99's Avatar
    Join Date
    May 2002
    Location
    Canadian Tundra
    Search Comp PM
    In VB6, I'm trapping another program on a blank form using the API SetParent. That part works fine except some of the shortcut keys of the original app don't work within the new parent window. The "alt + Key" shortcuts and simulated or real key presses work and menu selection by mouse clicks are all ok but not the "ctrl + key" nor the functions keys (F1 - F12) or the (esc) key. Even when pressed from the keyboard while the app has focus they are not received or acted upon by the original menus. If I return the program to it's original parent's handle (.hwnd ) the keys all work as they should.

    Any ideas why those keys (simulated or real) don't work in a new window or have a workaround?
    Quote Quote  
  2. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    I know that this is pretty late, but..

    gll99, I don't VB6 (though every time I see VB, I think (and see) MS Access because that
    is what I use a lot of these days at work) and I've even createa a few Pascal .dll 's and then
    imported them into the ms access programming interfeace where they actually do work, go
    figure. Anyway. I was just sharing a past experience from a few years ago or so. Back to
    the topic, now..

    Ahh... I know that in Pascal (delphi) in order to trap these special keys, you have to use
    the *other* event routines of the control in question and use thier respective keyboard
    event calling routine, I think they go something like this:

    --> if (Shift value + key) = xyz then ...

    Your problem might have to do with the way the keyboard is being interpreted and then setting
    up the necessary even routines and their variables, etc., and perhaps this might help you to
    figure it out on your (VB6) end, below.

    So, in Pascal, (as an example) there are several keyboard event routines to choose and call:

    In this example, notice the single reference for obtaining the 'key' value typed by the user. This
    would not work for your situation..

    Code:
    procedure TForm1.eb_InputKeyPress(Sender: TObject; var Key: Char);
    begin
    
    end;
    But, maybe this would, in your VB6 equivalent..

    Code:
    type 
      TShiftState = set of (ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble);
    
    procedure TForm1.eb_InputKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      // capture the (Shift + key) to get the actual key-combo.. ie, Ctrl+C or Alt+A, etc.
    
    end;
    Description

    The TShiftState type is used by key-event and mouse-event handlers to determine the state of
    the Alt, Ctrl, and Shift keys and the state of the mouse buttons when the event occurs. It is a
    set of flags that indicate the following:


    Code:
    Value       Meaning
    -----       -------
    ssShift	The Shift key is held down.
    ssAlt	      The Alt key is held down.
    ssCtrl	The Ctrl key is held down.
    ssLeft	The left mouse button is held down.
    ssRight	The right mouse button is held down.
    ssMiddle	The middle mouse button is held down.
    ssDouble	The mouse was double-clicked.

    or,

    Code:
    procedure TForm1.eb_InputKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      // capture the (Shift + key) to get the actual key-combo.. ie, Ctrl+C or Alt+A, etc.
    
    end;
    Occurs when the user releases a key that has been pressed.

    Code:
    type
      TKeyEvent = procedure (Sender: TObject; var Key: Word; Shift: TShiftState) of object;
    property OnKeyUp: TKeyEvent;
    Description

    Use the OnKeyUp event handler to provide special processing that occurs when a key is released.
    The OnKeyUp handler can respond to all keyboard keys, including function keys and keys combined
    with the Shift, Alt, and Ctrl keys.

    The TKeyEvent type points to a method that handles keyboard events. The Key parameter is the
    key on the keyboard. For non-alphanumeric keys, you must use virtual key codes to determine the
    key pressed. For more information, see Virtual Key codes.

    The Shift parameter indicates whether the Shift, Alt, or Ctrl keys are combined with the keystroke.


    ...

    The following code aborts a print job if the user presses Esc. Note that you should setKeyPreview to True to ensure that the OnKeyDown event handler of Form1 is called.

    Code:
    procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    begin
    if (Key=VK_ESCAPE) and Printer.Printing then
      begin
      Printer.Abort;
      MessageDlg('Printing aborted', mtInformation, [mbOK],0);
      end;
    end;
    Virtual Key codes provide a symbolic representation of user key presses.

    Unit

    Windows

    Description


    Virtual key codes allow you to represent keyboard values for non-alphanumeric keys.Windows defines
    special constants for each key the user can press. These constants can then be used to refer to the
    keystroke in Windows API calls or in an OnKeyUp or OnKeyDown event handler.

    Most of the virtual key codes are defined in the Windows unit. Additional key codes may be defined in
    special-purpose Windows wrappers such as the imm unit. For alphabetic keys, you should use ord with
    an uppercase character, for example, ord( 'M' ). To create a virtual key code for an alphanumeric value,
    use the Ord method. For example the virtual key code for ‘7’ is Ord(‘7’).

    The following table lists the virtual key codes defined in the Windows unit:


    Code:
    Virtual Key Code	Corresponding key
    
    VK_LBUTTON   Left mouse button
    VK_RBUTTON   Right mouse button
    VK_CANCEL    Control+Break
    VK_MBUTTON   Middle mouse button
    VK_BACK      Backspace key
    VK_TAB       Tab key
    VK_CLEAR     Clear key
    VK_RETURN    Enter key
    VK_SHIFT     Shift key
    VK_CONTROL   Ctrl key
    VK_MENU      Alt key
    VK_PAUSE     Pause key
    VK_CAPITAL   Caps Lock key
    VK_KANA      Used with IME
    VK_HANGUL    Used with IME
    VK_JUNJA     Used with IME
    VK_FINAL     Used with IME
    VK_HANJA     Used with IME
    VK_KANJI     Used with IME
    VK_CONVERT   Used with IME
    
    VK_NONCONVERT Used with IME
    VK_ACCEPT     Used with IME
    VK_MODECHANGE Used with IME
    VK_ESCAPE   Esc key
    VK_SPACE    Space bar
    VK_PRIOR    Page Up key
    VK_NEXT     Page Down key
    VK_END      End key
    VK_HOME     Home key
    VK_LEFT     Left Arrow key
    VK_UP       Up Arrow key
    VK_RIGHT    Right Arrow key
    VK_DOWN     Down Arrow key
    VK_SELECT   Select key
    VK_PRINT    Print key (keyboard-specific)
    VK_EXECUTE  Execute key
    VK_SNAPSHOT Print Screen key
    VK_INSERT   Insert key
    VK_DELETE   Delete key
    VK_HELP     Help key
    
    VK_LWIN     Left Windows key (Microsoft keyboard)
    VK_RWIN     Right Windows key (Microsoft keyboard)
    VK_APPS     Applications key (Microsoft keyboard)
    VK_NUMPAD0  0 key (numeric keypad)
    VK_NUMPAD1  1 key (numeric keypad)
    VK_NUMPAD2  2 key (numeric keypad)
    VK_NUMPAD3  3 key (numeric keypad)
    VK_NUMPAD4  4 key (numeric keypad)
    VK_NUMPAD5  5 key (numeric keypad)
    VK_NUMPAD6  6 key (numeric keypad)
    VK_NUMPAD7  7 key (numeric keypad)
    VK_NUMPAD8  8 key (numeric keypad)
    VK_NUMPAD9  9 key (numeric keypad)
    
    VK_MULTIPLY	 Multiply key (numeric keypad)
    VK_ADD       Add key (numeric keypad)
    VK_SEPARATOR Separator key (numeric keypad)
    VK_SUBTRACT  Subtract key (numeric keypad)
    VK_DECIMAL   Decimal key (numeric keypad)
    VK_DIVIDE   Divide key (numeric keypad)
    VK_F1        F1 key
    VK_F2        F2 key
    VK_F3        F3 key
    VK_F4        F4 key
    VK_F5        F5 key
    VK_F6        F6 key
    VK_F7        F7 key
    VK_F8        F8 key
    VK_F9        F9 key
    VK_F10      F10 key
    VK_F11      F11 key
    VK_F12      F12 key
    VK_F13      F13 key
    VK_F14      F14 key
    VK_F15      F15 key
    VK_F16      F16 key
    VK_F17      F17 key
    VK_F18      F18 key
    VK_F19      F19 key
    VK_F20      F20 key
    VK_F21      F21 key
    VK_F22      F22 key
    VK_F23      F23 key
    VK_F24      F24 key
    VK_NUMLOCK  Num Lock key
    VK_SCROLL   Scroll Lock key
    VK_LSHIFT   Left Shift key (only used with GetAsyncKeyState and GetKeyState)
    VK_RSHIFT   Right Shift key (only used with GetAsyncKeyState and GetKeyState)
    VK_LCONTROL Left Ctrl key (only used with GetAsyncKeyState and GetKeyState)
    VK_RCONTROL Right Ctrl key (only used with GetAsyncKeyState and GetKeyState)
    
    VK_LMENU     Left Alt key (only used with GetAsyncKeyState and GetKeyState)
    VK_RMENU     Right Alt key (only used with GetAsyncKeyState and GetKeyState)
    VK_PROCESSKEY Process key
    VK_ATTN      Attn key
    VK_CRSEL     CrSel key
    VK_EXSEL     ExSel key
    VK_EREOF     Erase EOF key
    VK_PLAY      Play key
    VK_ZOOM      Zoom key
    VK_NONAME    Reserved for future use
    VK_PA1       PA1 key
    VK_OEM_CLEAR Clear key
    -vhelp 4536
    Quote Quote  
  3. Renegade gll99's Avatar
    Join Date
    May 2002
    Location
    Canadian Tundra
    Search Comp PM
    Thanks vhelp. It's not too late since I still haven't solved this completely although I'm working around it now.

    I was already using the virtual keycode constants with the Sendmessage and Postmessage Functions and that didn't work. I also tried sendkeys and sending the characters needed for F6. I tried the keyboard directly and that didn't work either.
    ie...
    Postmessage sends the key to a specific window identified by it's .hwnd and sendkeys just sends to the active window:
    Call PostMessage(lVDUBcapwnd, WM_KEYDOWN, VK_F6, 0)
    SendKeys vbKeyF6, True or SendKeys ("F6"), True

    These methods work when the window is not trapped so I know they are ok.

    The program I'm trapping is Virtualdubmod mpeg2 because I want to create my own timer program. There are a few timer programs available but I don't find them user friendly. There is a version of virtualdubmod with a built-in timer but the capture still uses vfw drivers only and I want to use the wdm drivers in more recent versions of virtualdubmod.

    I looked at this again lately and noticed that when vdubmod is trapped, sending or manually pressing any keys except the alt/key combination changes the tv channel to the numeric value of the key. So it's not that the key is not being read but as you said it seems to be misinterpreted and misdirected to the wrong field.

    The only reason I wanted to use the function keys is because the options to start the capture are F5 or F6 and I don't know how to get the one I want. If I just send the alt/key combination "%(C)" which is (alt/C) followed by "%(v)" which is (alt/v) to start the capture there is no way to know if it defaults to F5 or F6. I need F6. To stop the capture I also have to send an "escape" key when the capture time is up. ie... Call PostMessage(lVDUBcapwnd, WM_KEYDOWN, VK_ESCAPE, 0) or SendKeys "{ESC}", True

    Right now I get around this by releasing the window just before issuing the "F6" key and before sending the "escape" and then re-trap it right after the capture is done.

    I know I don't need to trap virtualdubmod at all to make the timer program work but it's better to take control of the whole or parts of the program. In one test, trapping the whole capture window to one of my forms and issuing a fullscreen resize, maximizes vdub to the size of the new parent form instead of the screen which is really great for placement and sizing. In another test trapping individual parts like the tv display window on one form and the capture counts and taskbar windows on 2 other forms and placing them elsewhere on the screen creates a custom look almost seems like having a new capture program.

    So for me, part of this exercise is the timer feature I am designing which doesn't really need to trap virtualdub for its basic functioning and the other is experimenting with the api taking ownership of different parts of the original program.
    Quote Quote  
  4. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    I was wondering and had a question. I'm working on some macro ideas for my company.
    And I came across an issue. There are some windows applications that somehow seem
    to either lock or suspend certain widnows function or event receiving what-have-you.

    In one of those nonsense, there was a priviately made windows app, and in another,
    there is the internet explorer windows where they have flash and other action-buttons
    (AB) that do something when the user click on the AB. But problem with that is that
    they don't have a way to activate other than the direct mouse clicks.

    However, when I use a third-party macro tool, those windows app seems to wake up
    and I can code up some macros for them (with their macro tool) and they will work all of
    the sudden, though with unexplained glitches once in a while.

    So developing marcos for those tools don't seem to be feasable on my own unless I use
    a third-party tool.

    So how does all this relate to yours, you might be asking ?

    well, prob nothing. Or, maybe not. Anyway. The thing is, maybe virtualdub is acting
    in the same way I just discribed for mine situation, above.

    I haven't read through everything you said in your last post above, but I was wondering
    if you describe what function you are trying to call up via your home-brew VB6 code so
    that I might have a go at it to see if I will have the same problem, though with Pascal
    code. I'm curious

    -vhelp 4565
    Quote Quote  
  5. Renegade gll99's Avatar
    Join Date
    May 2002
    Location
    Canadian Tundra
    Search Comp PM
    @vhelp
    There is nothing very special about my code I'm just using the "findwindow" api function to get the vdub hwnd and then using the "setparent" api function to trap the vdub window on one of my form. I've tried a few slightly more complex traps like hooking just the vdub video window, the capture feedback window and taskbar onto separate forms but that won't be part of the end product.

    Everything I've designed is very crude and filled with extra test code, buttons, feedback text boxes and labels but it basically works. I can start and stop a single capture session via timer and everything works but I have a lot of cleanup to do and lot's of code to fix. I also have to expand the scheduler for multiple captures and include a tuner change.
    -----------------------------------------------------------------------------------------------------------------------------
    I am using Virtualdub-mpeg2 v 1.6.19 in my tests

    Without programming anything, if you just load up vdub and then open the capture window the F5 or F6 function key is used to start the capture. From the capture window you can also use the menu shortcuts alt/C followed by alt/V to start the capture. F6 allows multiple file io capture. The alt/c and alt/v combination doesn't specify which option is the default. That is why I want to activate the capture using F6 since long captures can exceed the 4gb limit.

    The menu shortcuts can be programmed and work fine but I think the problem is that although I target the vdub capture window by its hwnd, the "function keys" only work on the top level window as programmed by the vdub key handler. When we first open vdub it is a top level window. When the capture window is open it too is a separate top level window. When I trap the capture window it becomes a child window of my form and is therefore no longer a top level window. When I release it then the function keys work. Like I said, this happens whether I press F6 on the keyboard or do it within my program.

    I don't think there's a way around this. I now release the capture window, send the F6 and then rehook the capture window and that works. It's not my preferred method but it works so I think I'll continue this way unless something new pops up.

    btw) Programming mouse clicks wouldn't work with this app. If you look at the capture menu you'll see what I mean. It would be the same as alt/C followed by alt/v and leave me with the same question about which capture function was activated since they are on the same menu line.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!