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
System wide Keyboard 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
look at PBSOL library http://pbosl.purearea.net/ .
There is a library to manage keyboard hooking in very easy way.
Good luck
There is a library to manage keyboard hooking in very easy way.
Good luck
with love from Uruguay
Thanks for the tip.wcardoso wrote:look at PBSOL library http://pbosl.purearea.net/ .
There is a library to manage keyboard hooking in very easy way.
Good luck
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.
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.
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
I searched through the libraries, but I can't find it - can you tell me where it is?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!


