Solved

about "WH_JOURNALRECORD" hook.

Posted on 2002-06-18
15
432 Views
Last Modified: 2010-04-04
hi experts,
   i want to cancel the input in windows when hold up the key 'a..z' this my code,it can holp up the message,but not cancel the input ,how can i do?
  thanks!

unit Unit1jphook3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    function IsKey(lp: integer):boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  hook:integer;
implementation

{$R *.dfm}
function tform1.IsKey(lp: integer):boolean;
begin
  result:=false;
  case lp of
    7745: result := true; {A}
    12354: result := true;{B}
    11843: result :=true; {c}
    8260: result := true; {d}
    4677: result := true; {e}
    8518: result := true; {f}
    8775: result := true; {g}
    9032: result := true; {h}
    5961: result := true; {i}
    9290: result := true; {j}
    9547: result := true; {k}
    9804: result := true; {l}
    12877: result := true;{m}
    12622: result := true;{n}
    6223: result := true; {o}
    6480: result := true; {p}
    4177: result := true; {q}
    4946: result := true; {r}
    8019: result := true; {s}
    5204: result := true; {t}
    5717: result := true; {u}
    12118: result := true;{v}
    4439: result := true; {w}
    11608: result := true;{x}
    5465: result := true; {y}
    11354: result := true;{z}
  end;
end;

function hookproc(icode:integer;wpadram:wparam;lparam:lparam):lresult;stdcall;
var
evtmsg:teventmsg;
begin
evtmsg:=peventmsg(lparam)^;
if evtmsg.message=WM_keyDOWN then
  begin
    if form1.IsKey(evtmsg.paramL)=true then
         //how can i cancel the messgae???????  
    else
         //
   end;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
hook:=setwindowshookex(WH_JOURNALRECORD,hookproc,hinstance,0);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
unhookwindowshookex(hook);
hook:=0;
end;

end.
0
Comment
Question by:hgbdelphi
  • 7
  • 6
  • 2
15 Comments
 

Expert Comment

by:penich
ID: 7091685
I think you can initiate "DEL" button pressed message
Something like
if form1.IsKey(evtmsg.paramL)=true then      
  SendMessage(form1.hwnd, WM_keyDOWN , VK_DELETE, nil)

0
 
LVL 33

Expert Comment

by:Slick812
ID: 7091690
I've done some things with the WH_JOURNALRECORD hook, but I do not understand your question - -
"i want to cancel the input in windows when hold up the key 'a..z'"  Do you mean that you want to Block all the Keboard input for that so that Nothing will recieve that keyboard letters A..Z, ,  The journalrecord is not like other "HOOK" types, you can not block the message by not passing it to the next Hook.  -

Result := CallNextHookEx(Hook, Code, wParam, Longint(@EventStrut) );

you don't even have that in your code. I don't think you can cancel the input with journal. Here's a way to get char from the LParam

if Chr(LOBYTE(LOWORD(evtmsg.paramL)))='A' then
0
 
LVL 33

Expert Comment

by:Slick812
ID: 7091698
hello penich, it's kind of a tradition at EE to post comments and not proposed answers, to keep a question open for furthur comment, and you should test your code first to see if it does the trick
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:hgbdelphi
ID: 7091889
thanks to  Slick812 and penich expert!
  i am jackaroo about program ,and in EE i have little points,so sorry to you.
  Slick812,my english is poor,sorry.your mean is that
use WH_JOURNALRECORD hook only Block the message and can not cancel you do example  input a char in edit????
  if no another ways i will do this by penich's way,
postmessage(form1.edit1.Handle, WM_keyDOWN , VK_BACK, 0)
it can del you input.
   please give me an answer!thanks!
0
 

Expert Comment

by:penich
ID: 7091938
I think I have another idea ;)

You can try to handle if user pressed button from your list ['a..z']. Rigth after that you can look through all the controls on your window and lock them (There is a standars windows message to change the state of the window to LOCKED or UNLOCKED).
if another button was pressed then UnLock all the controls if they were locked earlier.
0
 

Author Comment

by:hgbdelphi
ID: 7092137
>>There is a standars windows message to change
>>the state of the window to LOCKED or UNLOCKED
i don't find the message,please talk me.
i use LockWindowUpdate,or edit1.enabled:=false do not work well,tell me please.thanks!
0
 

Author Comment

by:hgbdelphi
ID: 7092152
i think lock can not work well,because it only lock the edit but will not delete the input.
0
 
LVL 33

Expert Comment

by:Slick812
ID: 7093754
If you only want to cancel keboard input to your Delphi application then you can just get the keyboard messages in the Application.OnMessage event and and set Handled to True. Do you need code for that?
0
 

Author Comment

by:hgbdelphi
ID: 7094223
 Slick812 ,thanks!but if i use Application.OnMessage ,it can only cancel the input of my delphi application,i want to all windows,so it can not do it.
  if  use WH_JOURNALRECORD hook only Block the message and can not cancel the input?
0
 
LVL 33

Expert Comment

by:Slick812
ID: 7094709
the WH_JOURNALRECORD hook was created and is used for "Journaling" (which is recording or keeping track of) the mouse and keyboard events. As I said before, it DOES NOT allow you to Block, Cancel or change ANY keyboard or mouse event. . . . it just receives (gets) the mouse and keyboard messages. I do not know of any way to block keboard input to OTHER applications except with a WH_KEYBOARD hook thats in a .DLL library. I have not ever used it to block keyboard but the API Help says


"To prevent Windows from passing the message to the rest of the hook chain or to the target window procedure, the return value must be a nonzero value. To allow Windows to pass the message to the target window procedure, bypassing the remaining procedures in the chain, the return value must be zero"

I don't have time now to try and get a WH_KEYBOARD hook procedure set up and running. You might do a search here at EE to see if someone has done that.
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 50 total points
ID: 7094732
this question is still Locked? You might should accept or reject the answer?
0
 

Author Comment

by:hgbdelphi
ID: 7094781
i think this answer is not very well,i still not understand
the WH_JOURNALRECORD hook can do it or not.so i reject.sorry!
0
 

Author Comment

by:hgbdelphi
ID: 7094786
Slick812 :
  thanks ,i will do it by dll or not another ways.
  very happy to meet you!
to all:
  thanks!
0
 
LVL 33

Expert Comment

by:Slick812
ID: 7097796
it's good to meet you also, , , , ,
I wonder why you need to block the keboard input to Other applications, just the letters A..Z and not the others (like +, =, {.? !) ? ? ?
0
 

Author Comment

by:hgbdelphi
ID: 7097803
Slick812,
   i do not know either:),this is my friend ask me,but i don't know.so i need you help.:)
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 158
Newbie Thread Programming 1 152
Comparing dates in Delphi. Greater than/ Less than 3 154
select query - oracle 16 100
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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