It is currently Thu Jun 20, 2013 4:07 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject:
PostPosted: Wed Mar 19, 2003 9:46 am 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by Caliban.

By searching this Forum i have found a Hook examble, i have it modifyt:

Code:
Global hhook
Global AlreadyPop
AlreadyPop = 0
Hooked$ = "No"
#MenuPopR = 44
#MenuPopL = 45

Procedure Hook(nCode, wParam, lParam) 

beep_(50,100) 

  ProcedureReturn 1
EndProcedure

Procedure HookProc(Hooked$) 
  Shared hhook           
 
  Select Hooked$     
    Case "Yes"     
      hInstance = GetModuleHandle_(0)     
      lpdwProcessId = GetWindowThreadProcessId_(WindowID, 0)     
      hhook = SetWindowsHookEx_(#WH_Keyboard, @Hook(), hInstance, lpdwProcessId)       
    Case "No"     
      UnhookWindowsHookEx_(hhook)       
    EndSelect 
EndProcedure

OpenWindow(0,250,250,250,250,#PB_Window_SystemMenu,"test")

CreateGadgetList(WindowID())
ButtonGadget(1,10,10,70,30,"UnHooked")
StringGadget(2,10,50,70,20,"Zum Testen")


Repeat
  EventID =  WaitWindowEvent()
  Select EventID
   
    Case #PB_EventCloseWindow
      Exit = 1
     
    Case #PB_EventGadget
      If EventGadgetID() = 1
          If GetGadgetText(1) = "Hooked"
            SetGadgetText(1,"UnHooked")
            HookProc("No")
          Else
            SetGadgetText(1,"Hooked")
            HookProc("Yes")
          EndIf         
      EndIf
       
    Case #WM_RBUTTONDOWN
      MessageRequester("UnHooked","Rechtemaustaste!",0) 
  EndSelect
 
Until Exit = 1

UnhookWindowsHookEx_(hhook)

End


But i like a Program tht Golobal get Keybord messages,
my Program only works in his own Window.

Has anyone a Answer ?

[PS: Pleas forgiv my English]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 25, 2003 5:53 pm 
Offline
New User
New User
User avatar

Joined: Fri Apr 25, 2003 5:31 pm
Posts: 9
Location: Iceland
Your code is creating a local hook. You have to set a global hook to catch the events if your application hasn't the focus. Change that line
Code:
hhook = SetWindowsHookEx_(#WH_Keyboard, @Hook(), hInstance, lpdwProcessId)

to
Code:
hhook = SetWindowsHookEx_(#WH_Keyboard, @Hook(), hInstance, 0)


But now you have to put your callback procedure in a DLL. Here can you get more informations about hooking.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye