Solved

Send an url to the current active browser

Posted on 2004-10-01
5
251 Views
Last Modified: 2010-04-05
 Greeting experts!
  I need to know how I can do the following:

  *)Capture hot key with specific programs (for example, if the current active window is internet explorer, F1 key will be captured to my program (running in the background), but if the current active window is others, F1 key will function normally).
  *)If the current window is a browser, how can I send an url to it and force it go there? (in the current browser window, not open a new one).
  It's hard for me to figure out myself, so your help is very useful to me.

  Thanks in advance!
  Tri
0
Comment
Question by:dttri
  • 3
5 Comments
 
LVL 6

Expert Comment

by:so3
Comment Utility
On the second question do you want to do it with a shortcut key or from the app and there is a file url or just a url
0
 
LVL 6

Expert Comment

by:so3
Comment Utility
i have a sample of what you want to do and tomorow i'll send it to you after you answer the question above
0
 
LVL 7

Author Comment

by:dttri
Comment Utility
 Thanks for you reply,
  My idea is this: for example, my current window is Internet Explorer, after I press F1 key (the F1 key associated with the help is disable), my current window will point to, eg, microsoft.com and go to it too.

  Waiting for your code,
  Tri
0
 
LVL 6

Accepted Solution

by:
so3 earned 500 total points
Comment Utility
Here is the code. Put a Thotkey on your form.

The code is not complete you have to find the handle of edit. I don't know what i'm doing wrong that i can't find it. Maybe you or some expert can find it . I'll try tomorrow to find it now i'm to tired:)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls,Menus,SHELLAPI;

type
  TForm1 = class(TForm)
    HotKey1: THotKey;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    Procedure HotKeyProc(var msg:TWmHotkey); message WM_HOTKEY;
  public
    { Public declarations }
    procedure RegisterShortcut(HKey: TShortCut);
    procedure UnRegisterShortCut;
  end;

var
  Form1: TForm1;
  Hotkey: integer;

implementation

{$R *.dfm}
procedure TForm1.RegisterShortcut(HKey:TShortCut);
var
  fuModifiers : Cardinal;
  Key: Word;
  Shift: TShiftState;
begin
  fuModifiers := 0;

  ShortCutToKey(HKey, Key, Shift);

  if  ssCtrl in Shift then
    fuModifiers := MOD_CONTROL;
  if ssShift in Shift then
    fuModifiers := fuModifiers or MOD_SHIFT;
  if ssAlt in Shift then
    fuModifiers := fuModifiers or MOD_ALT;  

  RegisterHotKey(Handle,HotKey,fuModifiers, Key);
end;

procedure TForm1.UnRegisterShortCut;
begin
  UnRegisterHotkey(Handle, HotKey);
  GlobalDeleteAtom(HotKey);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  UnRegisterShortCut;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    HotKey:=GlobalAddAtom(PChar('F1'));
    RegisterShortcut(HotKey1.HotKey);
end;

function FindControlByNumber(hApp: HWND; ControlClassName: string; ControlNr: Word = 1): HWND;
var
  i: Word;
  hControl: HWND;
begin
  Result := 0;
  if IsWindow(hApp) then
  begin
    Dec(ControlNr);
    hControl := 0;
    for i := 0 to ControlNr do
    begin
      hControl := FindWindowEx(hApp, hControl, PChar(ControlClassName), nil);
      if hControl = 0 then
        Exit;
    end;
  end;
  Result := hControl;
end;

procedure TForm1.HotkeyProc(var Msg: TWmHotkey);
var Whandle,hEdit: HWND;
    Clas:array[0..127] of Char;
begin

if MSG.HotKey = Hotkey then begin
  Whandle:=GetForegroundWindow;
  GetClassname(Whandle,Clas,Sizeof(Clas));

  if (Whandle<>0) and (Clas='IEFrame') then
       begin
        hEdit := FindControlByNumber(Whandle, 'Edit', 1);      //here is the pb where to find the IE edit handle
        if hEdit <> 0 then        //329586
          begin
           SendMessage(hEdit, WM_SETTEXT, 0, Integer(PChar('http://www.microsoft.com')));
           SendMessage(hEdit, WM_KEYDOWN, VK_RETURN, 0);
           SendMessage(hEdit, WM_KEYUP, VK_RETURN, 0);
          end;
       end
       else
         begin
         UnRegisterHotkey(Handle, HotKey);
         SendMessage(Whandle, WM_KEYDOWN, VK_F1, 0);
         Sleep(1000);
         SendMessage(Whandle, WM_KEYUP, VK_F1, 0);
         RegisterShortcut(HotKey1.HotKey);
         end;

  end;
end;

end.
0
 
LVL 3

Expert Comment

by:gandalf_the_white
Comment Utility
you can put the ie in the foreground and send the key F4
it will set the cursor into the adress bar and show the history
now you only need to send the whole adress at once
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now