Solved

popup letters without pressing keyboard

Posted on 2001-08-25
9
280 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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 34

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

840 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