?
Solved

Which function to select an entried word ?

Posted on 2003-03-04
10
Medium Priority
?
154 Views
Last Modified: 2010-04-04
I use JournalRecord to spy keyboard input as well.
I would like to select an entried word at cursor while typing in any application. If the key sequence match my bogus wordlist, it will replace that bogus word on the fly.

Ex:  typing 'ducking' it will change to '****ing'.

One more thing, How to search a keyword data in real time?
I have a bogus wordlist in text file.
0
Comment
Question by:tong111797
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 2

Expert Comment

by:Krakken
ID: 8066419
If I understand you right this should help?

Just buffer the entered text until a space is entered then use this on the string before saving it.

E.G. Buffer := stSub(Buffer, 'badword', '****');

// REPLACES strRep WITH strWith IN strCont //
function stSub(strCont, strRep, strWith: STRING): STRING; var
  locRep, lenRep: INTEGER;
  strTst: STRING;

begin
  while pos(strRep, strCont) > 0 do begin
    locRep := pos(strRep, strCont);
    lenRep := length(strRep);

    strCont := trim(copy(strCont, 0, locRep - 1) +strWith+
               copy(strCont, locRep + lenRep, length(strCont)));
  end;

  RESULT := strCont;
end;
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8068795
hello tong, I believe the TEVENTMSG of the journal rec has the destination windows Handle in the hwnd. . . . you can send a WM_CHAR message to that window with a #8, , for a Backspace key, for as many charaters as needed, then send the WM_CHAR message for the new charaters (I guess '*'), ,  selecting and replacing in another process, may take alot of coding, I may have some time later to look
0
 

Author Comment

by:tong111797
ID: 8072543
Thank stick812 it is a good idea.
Is it fast and doesn't interrupt human typing ?

--
note

I load bogus wordlists into Tstringlist and there are FIND function for Tstringlist.


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Slick812
ID: 8076726
OK, here's some code that works in notepad,


var
  Form1: TForm1;
  JHook: Integer;
  CharAry: Array[0..7] of Char;
  PCharAry: Array[0..5] of Pchar;
  LastFocus: Integer;
{IMPORTANT - - set the length of your CharAry
to One More than the Longest string in your
PCharAry, , , if your Longest PChar word is
GRABBIGTITS
then make your
CharAry: Array[0..11] of Char;}


procedure TForm1.FormCreate(Sender: TObject);
begin
CharAry[7] := #0;
{make the last char a #0}

{I used a PChar Array for the Censored words,
because of the StrLComp( ) function}

{IMPORTANT ! !
ALL PChar words are SPELLED BACKWARDS
REKOOH  == HOOKER
and are ALL CAPITALS}
PcharAry[0] := 'REKOOH';
PcharAry[1] := 'OJOM';
PcharAry[2] := 'REPMUH';
PcharAry[3] := 'BOJWONS';
PcharAry[4] := 'YTSAT';
PcharAry[5] := 'YNEEW';
end;


function JourProc(Code, wParam: Integer; var EventStrut: TEVENTMSG): Integer; stdcall;
var
Byte1: Byte;
i, j, FocusWnd: Integer;
Pt1: TPoint;
begin
{this is the JournalRecordProc}
Result := CallNextHookEx(JHook, Code, wParam, Longint(@EventStrut));
{the CallNextHookEX is not really needed for journal hook since it it not
really in a hook chain, but it's standard for a Hook}
if (Code < 0) or (Code = HC_SYSMODALON) then Exit;
{you should cancel operation if you get HC_SYSMODALON}

if Code = HC_ACTION then
  begin
  if (EventStrut.message = WM_KEYUP) then
    begin
    Pt1.x := 0;
    Pt1.y := 0;
    GetCaretPos(Pt1);
    if (Pt1.x = 0) and (Pt1.y = 0) then Exit;
    Byte1 := LOBYTE(LOWORD(EventStrut.paramL));
      if Byte1 = 8 then
        begin
        Move(CharAry[1],CharAry[0],6);
        Exit;
        end;
    Form1.Label1.Caption := 'Char '+ IntToStr(Pt1.x);
    if (Byte1 = 32) or ((Byte1 > 47) and (Byte1 < 58)) or ((Byte1 > 64) and (Byte1 < 91))
    or ((Byte1 > 185) and (Byte1 < 193)) or ((Byte1 > 218) and (Byte1 < 223))then
      begin
      FocusWnd := GetFocus;
      if FocusWnd <> LastFocus then
        begin
        LastFocus := FocusWnd;
        CharAry[0] := ' ';
        end;
      Move(CharAry[0],CharAry[1],6);
      if (Byte1 > 64) and (Byte1 < 91) then
      CharAry[0] := Chr(Byte1) else
      CharAry[0] := #32;
      Form1.Label6.Caption := CharAry;
      for i := 0 to High(PCharAry) do
        if StrLComp(CharAry, PCharAry[i], StrLen(PCharAry[i])) = 0 then
        begin
        for j := 0 to StrLen(PCharAry[i])-1 do
        SendMessage(FocusWnd, WM_CHAR, 8,0);
        for j := 0 to StrLen(PCharAry[i])-1 do
        SendMessage(FocusWnd, WM_CHAR, Ord('*'),0);
        Form1.Label5.Caption := 'Got a Word '+ IntToStr(Pt1.x)+' '+ IntToStr(FocusWnd);
        break;
        end;
      end;
    end;
  end;
end;


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

but it does not work for all text edit windows? ?
this is all I have time to do for a few days
0
 

Author Comment

by:tong111797
ID: 8082026
I tried all but couldn't get a good result.

SendMessage(FocusWnd,WM_CHAR,VK_BACK,0);
SendMessage(FocusWnd,WM_KEYDOWN,VK_BACK,0);
SendMessage(FocusWnd,WM_KEYUP,VK_BACK,0);
keybd_event(VK_BACK,0,0,0);


:~(
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8082104
maybe -

for j := 0 to StrLen(PCharAry[i])-1 do
  begin
  keybd_event(VK_BACK,0,0,0);
  keybd_event(VK_BACK,0,KEYEVENTF_KEYUP,0);
  end;

??????
0
 

Author Comment

by:tong111797
ID: 8092938
keybd_event(VK_BACK,0,0,0);
keybd_event(VK_BACK,0,KEYEVENTF_KEYUP,0);
Still didn't work. I also tried put Application.ProcessMessage;
before and/or after the command.

:~(

I found SendInput API but I don't know much and
couldn't find a example for delphi.

Thanks!
0
 

Author Comment

by:tong111797
ID: 8274466
I found the solution.
It need scancode.
I use PostKeyEx32 function from P. Below


    keybd_event( key, MapvirtualKey( key, 0 ), 0, 0 );
    keybd_event( key, MapvirtualKey( key, 0 ), KEYEVENTF_KEYUP, 0 );


0
 
LVL 1

Expert Comment

by:Computer101
ID: 8275157
A request for PAQ has been made.  If no response or you feel this is in error, comment.  If no objection, I will PAQ in three days.

Computer101
E-E Admin
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
ID: 8306978
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

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