System wide Keyboard Hook

Just starting out? Need help? Post your questions and find answers here.
Yogi Yang
Enthusiast
Enthusiast
Posts: 107
Joined: Sun Dec 11, 2005 2:19 pm

System wide Keyboard Hook

Post by Yogi Yang »

Has any one implemented system wide keyboard hook for remapping conventional keyboard?

I have got the hooking code in a Dll created using LCC C. I was wondering if such DLLs can be used in PB or not.

If yes how.

Thanks
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Yogi Yang
Enthusiast
Enthusiast
Posts: 107
Joined: Sun Dec 11, 2005 2:19 pm

Post by Yogi Yang »

SFSxOI wrote:Will this help:

viewtopic.php?t=16185&highlight=hook
I have already check that article.

It would not help me here as I do not want to install and monitor HotKeys. I want my program to hook into the Keyboard so that when every a key is pressed my software should know first about and sould change the content if required.

I have a good hooking mechanism in place I was wondering if I can use it easily from PureBasic. Currently I have a small utility for personal use programmed in Delphi but want to implement that same one in PureBasic for sake of learning and getting an ideas as to how easy, usefull and efficient PB is....

Thanks
wcardoso
User
User
Posts: 80
Joined: Fri Apr 25, 2003 5:06 pm
Location: Uruguay

Post by wcardoso »

look at PBSOL library http://pbosl.purearea.net/ .
There is a library to manage keyboard hooking in very easy way.
Good luck :wink:
with love from Uruguay
Yogi Yang
Enthusiast
Enthusiast
Posts: 107
Joined: Sun Dec 11, 2005 2:19 pm

Post by Yogi Yang »

wcardoso wrote:look at PBSOL library http://pbosl.purearea.net/ .
There is a library to manage keyboard hooking in very easy way.
Good luck :wink:
Thanks for the tip.
I will go through it. What actuall I want to do is to use the Hooking mechanism that I have with me in PB.

Thanks again.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Yogi Yang,

What did you finally end up using?
Yogi Yang
Enthusiast
Enthusiast
Posts: 107
Joined: Sun Dec 11, 2005 2:19 pm

Post by Yogi Yang »

I have not implemented anything in PB. My original implementation is in Delphi 3.

I want to implement in PB but the mechanism that is implemented is using memory mapped files to map into target applications memory space.

The code is Delphi is something like this:

procedure TForm1.FormCreate(Sender: TObject);
begin
sharedFileHandle := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, 256, 'YogiSharedFile');
sharedData := MapViewOfFile(sharedFileHandle, FILE_MAP_WRITE, 0, 0, 0);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
UnmapViewOfFile(sharedData);
CloseHandle(sharedFileHandle);
end;
// --------- This routine is executed (called) when ever user presses a key in any windows based apps

procedure TForm1.main(var msg: TMessage);
begin
msg.Result := 0; // the dll should not touch this keypress
LabelHandle.Caption := IntToStr(sharedData[0]); // handle of the current window
GHwnd := sharedData[0];
if char(msg.wParam) = 'Q' then begin
msg.Result := 1; // tell the dll to kill the original keypress

// *** THIS IS LINE IS REQUIRED TO
// *** REMAP ONLY KEYDOWNS
// *** THE MEAINING OF THE BITS CAN
// *** BE FOUND IN THE WIN32SDK HELP
// *** UNDER KEYWORD: "KeyboardProc"

if (msg.LParam and $80000000) = 0 then
PostMessage(sharedData[0], WM_CHAR, ord('*'), 1);
end;

if char(msg.wParam) = 'Z' then begin
msg.Result := 1; // tell the dll to kill the original keypress
//Delete previously typed character and insert another one
if (msg.LParam and $80000000) = 0 then begin
SendMessage(GHwnd, WM_KEYDOWN, VK_BACK, 0);
PostMessage(GHwnd, WM_CHAR, VK_BACK, 1);

SendMessage(sharedData[0], WM_KEYDOWN, $1FFF0001, 0);
PostMessage(sharedData[0], WM_CHAR, ord('M'), 1);

end;
end;

If you observe the code the implemeted Hook passes all the messages regarding keyboard to the delphi form. How can such a thing be possible in case of PB where forms are created in a way that I am not aware of. :(
mp303

Post by mp303 »

wcardoso wrote:look at PBSOL library http://pbosl.purearea.net/ .
There is a library to manage keyboard hooking in very easy way.
Good luck :wink:
I searched through the libraries, but I can't find it - can you tell me where it is?

thanks!
Post Reply