Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

about "WH_JOURNALRECORD" hook.

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
hgbdelphi
Asked:
hgbdelphi
  • 7
  • 6
  • 2
1 Solution
 
penichCommented:
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
 
Slick812Commented:
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
 
Slick812Commented:
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
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!

 
hgbdelphiAuthor Commented:
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
 
penichCommented:
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
 
hgbdelphiAuthor Commented:
>>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
 
hgbdelphiAuthor Commented:
i think lock can not work well,because it only lock the edit but will not delete the input.
0
 
Slick812Commented:
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
 
hgbdelphiAuthor Commented:
 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
 
Slick812Commented:
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
 
Slick812Commented:
this question is still Locked? You might should accept or reject the answer?
0
 
hgbdelphiAuthor Commented:
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
 
hgbdelphiAuthor Commented:
Slick812 :
  thanks ,i will do it by dll or not another ways.
  very happy to meet you!
to all:
  thanks!
0
 
Slick812Commented:
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
 
hgbdelphiAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now