Jump to content

simulating KeyPress in Delphi for change channel in dvbviewer


Dimonar

Recommended Posts

Hi.

I need to do a little separate program and part of this task is to "press" NextChannel button in DVBViewer. If I use real keyboard, I'd use a letter P to select next channel. So I need to simulate pressing P-button from my program.

I use Delphi7 and I think, this code with winAPI can be used:

 

procedure TForm1.Button1Click(Sender: TObject);
var
  wnd: HWND;
  i: Integer;
  s: string;
begin
  wnd := FindWindow('XXXX', nil);
  if wnd <> 0 then
  begin
    wnd := FindWindowEx(wnd, 0, 'XXXX', nil);

   s := 'p';               // key that controls channel in DVBViewer
      SendMessage(wnd, WM_CHAR, Word(s), 0);
  end;
end;

 

But I don't know what I should write instead of XXXX in FindWindow and FindWindowEx. I tried to find answers with Winspector, but there is a lot of names and I don't see right.

Could you help me, please?

Link to comment

Simply use the text in the title bar for lpWindowName (it's always the same):

 

FindWindow(nil,'DVBViewer');

 

or more precisely

 

FindWindow('TfrmMain','DVBViewer');

Link to comment

Griga, thank you for reply.

 

Now I use code:

 

 
begin
  wnd := FindWindow('TfrmMain', nil);
  if wnd <> 0 then
  begin
    label1.caption:='Yes1';
    wnd := FindWindowEx(wnd, 0, 'TfrmControl', nil);
    If  wnd <> 0 then   label1.caption:='Yes2';

    s := 'p';
    SendMessage(wnd, WM_CHAR, Word(s[i]), 0);
  end
  else  label1.caption:='No';
end;

 

And it seems working, but channel does not changed... May be I use incorrect lpszclass in FindWindowEx ? But "TfrmMain" is not suitable, because when I use it, I get wnd=0.

Where do I have a mistake?

Thank you.

Link to comment

Problem solved with

 

wnd := FindWindow('TfrmMain', nil);

if wnd <> 0 then

begin

PostMessage(wnd, WM_KEYDOWN, ord('P'),1);

PostMessage(wnd, WM_KEYUP, ord('P'),1);

label1.caption:='Yes1';

end

 

 

I should read more...

Edited by Dimonar
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...