Solved

about "WH_JOURNALRECORD" hook.

Posted on 2002-06-18
15
429 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:hgbdelphi
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
i think lock can not work well,because it only lock the edit but will not delete the input.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 33

Expert Comment

by:Slick812
Comment Utility
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
Comment Utility
 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
Comment Utility
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
Comment Utility
this question is still Locked? You might should accept or reject the answer?
0
 

Author Comment

by:hgbdelphi
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi 10 Seattle Dataset Actions 5 71
Working with hours 3 31
How to debug For loops? 3 33
Convert a string into a TDateTime 5 44
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 this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now