Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / January 2007

Tip: Looking for answers? Try searching our database.

How to Change Lparam before calling CallNextHookEx()?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nash - 25 Jan 2007 10:22 GMT
Hi All,
I am working on Message Hooking.I am trying to change the value of
lParam before calling CallNextHookEx() function.. and its value is
getting changed but the contents remains same.. Where as if I am able to
change wParam. For Eg: if I press any key 'S' and if I want to modify it
to 'B' by using wParam its possible.. Can u now please help me in
modifying this 'S' to 'B' using lParam?

Regards,
~Nash
Bruno van Dooren [MVP VC++] - 26 Jan 2007 10:29 GMT
> I am working on Message Hooking.I am trying to change the value of
> lParam before calling CallNextHookEx() function.. and its value is
> getting changed but the contents remains same.. Where as if I am able to
> change wParam. For Eg: if I press any key 'S' and if I want to modify it
> to 'B' by using wParam its possible.. Can u now please help me in
> modifying this 'S' to 'B' using lParam?

What hook ID are you using when you install the hook function?
Afaik, keyboard monitoring via a WH_KEYBOARD or WH_KEYBOARD_LL hook
is read only. i.e.you cannot change a B to an S.
The hook functions are just for monitoring afaik.

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Tamas Demjen - 26 Jan 2007 18:39 GMT
>>I am working on Message Hooking.I am trying to change the value of
>>lParam before calling CallNextHookEx() function.. and its value is
[quoted text clipped - 7 lines]
> is read only. i.e.you cannot change a B to an S.
> The hook functions are just for monitoring afaik.

On the other hand, you can discard a keyboard event from the keyboard
hook function but not calling CallNextHookEx, and use keybd_event to
emulate a substitute keystroke:

LRESULT CALLBACK Hook(int nCode, WPARAM wParam, LPARAM lParam)
{
   if(wParam == 'S')
   {
      keybd_event('B', ..., 0, ...);
      keybd_event('B', ..., KEYEVENTF_KEYUP, ...);
   }
   else
      CallNextHookEx(KeyHook, nCode, wParam, lParam);
}

Be very careful, as you can cause pretty severe damage to the system if
you misuse this hook, or issue the wrong keydb_event. You could get the
control or alt key stuck forever, or get a keystroke repeating forever,
or even all keystrokes permenently disabled, after which you have to
reboot to get it fixed.

Do this at your own risk.

Tom
Bruno van Dooren [MVP VC++] - 26 Jan 2007 22:13 GMT
> On the other hand, you can discard a keyboard event from the keyboard hook
> function but not calling CallNextHookEx, and use keybd_event to emulate a
> substitute keystroke:

Not calling CallNextHook only affects other hook functions, not regular apps
afaik.

> LRESULT CALLBACK Hook(int nCode, WPARAM wParam, LPARAM lParam)
> {
[quoted text clipped - 12 lines]
> even all keystrokes permenently disabled, after which you have to reboot
> to get it fixed.

Yeah. inserting keyboard events has the interesting side effect that your
hook function gets called.
So your keyboard hook inserts a char, for which it will get executed again,
for which it will insert...
I think that is primarily the reason why hooks are for monitoring purposes
only.
That and security of course.

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Tamas Demjen - 27 Jan 2007 01:26 GMT
> Not calling CallNextHook only affects other hook functions, not regular apps
> afaik.

I stand corrected.

I've used a keyboard hook to capture a special key combination, and
called keybd_event to issue another keystroke. I was under the
impression that I practically redefined a key. It looks like I was
completely wrong. It worked, as the original keystroke I intended to
replace did nothing at all.

Sorry for the confusion I have caused.

Tom

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.