Solved

popup letters without pressing keyboard

Posted on 2001-08-25
9
279 Views
Last Modified: 2010-04-06
how can i popup letters or like
pressing the enter key without pressing
keys in the keyboard.

 example: If im in the notepad(active window)
          after a few seconds a word will
          be written on it,(like it pops right away
          there!)
         
0
Comment
Question by:ryan_sabarre
9 Comments
 
LVL 1

Accepted Solution

by:
sundayboys earned 150 total points
ID: 6425855
procedure TForm1.Button1Click(Sender: TObject);
var
wnd:HWND;
i:integer;
s:string;
begin
 wnd:= FindWindow('notepad',nil);
 if wnd>0then
 begin
  wnd:=FindWindowEx(wnd,0,'Edit',nil);
  s:='Hello';
  For i:=0 to  Length(s) do
  SendMessage(wnd, WM_CHAR, Word(s[i]),0);
  PostMessage(wnd, WM_KEYDOWN, VK_RETURN,0);
  PostMessage(wnd, WM_KEYDOWN, VK_SPACE,0);
 end;
 end;
0
 

Author Comment

by:ryan_sabarre
ID: 6425869
Last Question
 if other kind of application, running
 and is the active window, how can i do
 this without going to my programming
 and pressing the onclick event button.
 like letting it happen for after a minute.
 
 
0
 

Author Comment

by:ryan_sabarre
ID: 6425874
What i mean i do not know the name of
the active window or application, and
i want to send some message on it
how can i do this? and is it possible
to display all application names found
who are running in my computer
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6425907
Hello

 Use winsight32 that come with delphi, to show all the running processes

  to get the handle for active window you use
GetForegroundWindow

The GetForegroundWindow function returns a handle to the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.
0
 

Author Comment

by:ryan_sabarre
ID: 6425915
You mean i will put it like this

procedure TForm1.Button1Click(Sender: TObject);
var
wnd:HWND;
i,r:integer;
s:string;
begin
wnd:=GetForegroundWindow;
//wnd:= FindWindow('Delphi 3',nil);
if wnd>0 then
begin
 wnd:=FindWindowEx(wnd,0,'Edit',nil);
 s:='Hello';
 For i:=0 to  Length(s) do
 SendMessage(wnd, WM_CHAR, Word(s[i]),0);
 PostMessage(wnd, WM_KEYDOWN, VK_RETURN,0);
 PostMessage(wnd, WM_KEYDOWN, VK_SPACE,0);
end
else
begin
 showmessage('not found');
end;
end;
0
 
LVL 1

Expert Comment

by:sundayboys
ID: 6425917
With the following routines it ist simply easy to kill a running process.First build a form with a TListview or Listbox with 3 columns and a button to refresh the running processes. The button must be binding with the efreshclick-procedure. The Listview shows the processes. With a Doubleclick on one of the processnames (binding with the doubleclick-propertie of Listvies) you can kill these running process. These is one of the simplest procedere to kill a running/hanging process under windows.

interface
uses
 {...,}TLHelp32 {important !}

// Global Variables, Globale Variablen

VAR aSnapshotHandle : THandle;
    aProcessEntry32 : TProcessEntry32;

procedure TFormMain.BtnRefreshClick(Sender: TObject);
var i       : integer;
    bLoop   : BOOL;
    NewItem : TListItem;
begin
  ListView.Items.Clear;
  aSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  aProcessEntry32.dwSize:=Sizeof(aProcessEntry32);
  bLoop:=Process32First(aSnapshotHandle,aProcessEntry32);
  while integer(bLoop) <>0 do
  begin
    NewItem:=ListView.Items.add;
    NewItem.Caption:=ExtractFileName(aProcessEntry32.szExeFile);
    NewItem.subItems.Add(IntToHex(aProcessEntry32.th32ProcessID,4));
    NewItem.subItems.Add(aProcessEntry32.szExeFile);
    ContinueLoop:=Process32Next(aSnapshotHandle,aProcessEntry32);
  end;
  CloseHandle(aSnapshotHandle);
end;

procedure TFormMain.ListViewDblClick(Sender: TObject);
var  Ret : BOOL;
     PrID : integer; //processidentifier
     Ph : THandle;  //processhandle
begin
  try
    with ListView do
    begin
      if MessageDlg('Do you want to Terminate "'+ItemFocused.Caption+'"?'+^J+
                    'posible the system is instabile or out of'+^J+
                    'control......',
          mtConfirmation,[mbYes,mbNo],0)=mrYes then
       begin
         PrID:=StrToInt('$'+ItemFocused.SubItems[0]);
         Ph:=OpenProcess(1,BOOL(0),PrID);
         Ret:=TerminateProcess(Ph,0);
         if Integer(Ret)=0 Then
           MessageDlg('Can Not Terminate "'+ItemFocused.Caption+'"',mtInformation,[mbOk],0)
         else
           ItemFocused.Delete;
       end;
     end;
   except
   end;
end;

procedure TFormMain.FormCreate(Sender: TObject);
begin
  //Application.OnHint := DisplayHint;  //If you want/need it...
  BtnRefreshClick(Sender);
end;

(Only Win95/Win98/ME)


0
 
LVL 20

Expert Comment

by:Madshi
ID: 6426089
I would suggest using keybd_event. It just simulates key pressed and doesn't care which application is currently in the foreground.

E.g. this one simulates pressing and releasing the control key:

  keybd_event(VK_CONTROL, 0, 0,               0);
  keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);

Regards, Madshi.
0
 
LVL 3

Expert Comment

by:lopem
ID: 6426768
listening...
0
 
LVL 33

Expert Comment

by:Slick812
ID: 6427513
if you use the keybd_event then this might help you to get the VK_ code for letters, VkKeyScan('m'), this will only get the small m you will have to use the
keybd_event(VK_SHIFT, 1, 0, 0);
to get upper case
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

777 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