473,385 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to Change Lparam before calling CallNextHookEx()?


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

--
nash
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Jan 25 '07 #1
4 6816
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.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Jan 26 '07 #2
Bruno van Dooren [MVP VC++] wrote:
>>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.
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
Jan 26 '07 #3
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)
{
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.
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.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Jan 26 '07 #4
Bruno van Dooren [MVP VC++] wrote:
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
Jan 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: **Developer** | last post by:
I have a RichTextBox and I want to programmatically change the Insert/Overwrite mode. I tried the following but it doesn't appear to change the mode. Pressing the Insert or Ins key does change...
2
by: Ryan Ross | last post by:
Hello, I need some help with the SendMessage method. I've imported it into C# with the following statement: public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, long wparam, int...
10
by: Patty O'Dors | last post by:
Hi In trying to create a RICHEDIT-derived ActiveX control in ATL, I've managed to successfully implement the stock font property, thanks for all your help on this. I'm now stuck on receiving...
4
by: crafuse | last post by:
Hello, I've overridden the WndProc function in my form to hand some special behavior. Specifically, I look for the WM_NCMOUSEMOVE event to tell me when the user is trying to move the window by...
5
by: SpotNet | last post by:
Hi Newsgroup, While trying to customise my common dialogs and learn C#, I'm having trouble getting this to work; OFNOTIFY ofny = (OFNOTIFY)Marshal.PtrToStructure(lParam, typeof(OFNOTIFY)); ...
3
by: Nick | last post by:
Hi there, I'm trying to emulate mouse clicks using WM_LBUTTONDOWN, and WM_LBUTTONUP respectively. I can't quite remember how I am to create the lParam from the x and y coordinates, any imput on...
0
by: zeng.hui.stephen | last post by:
I download the demo http://msdn.microsoft.com/msdnmag/issues/02/10/cuttingedge/. I inherite the demo, and write my code. I want to use Hook to monitor C++ Edit change. I use a C# form...
0
by: nash | last post by:
Thanks all for reply.. one thing is sure we cant modify by using WH_KEYBOARD/WH_KEYBOARD_LL hook... I am using WH_GETMESAGE hhok to capture and modify the character.By Using wParam definitely we...
7
by: dzar | last post by:
I have an application that sends messages to other applications through PostMessage(HWND_BROADCAST, MY_MESSAGE_ID, wparam_float, lparam_float); in C (and this works... I can typecast and built byte...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.