Globaler Keyboard Hook (Win32)

Windowsspezifisches Forum , API ,..
Beiträge, die plattformübergreifend sind, gehören ins 'Allgemein'-Forum.
Benutzeravatar
Fluid Byte
Beiträge: 3110
Registriert: 27.09.2006 22:06
Wohnort: Berlin, Mitte

Beitrag von Fluid Byte »

Code: Alles auswählen

Structure KBDLLHOOKSTRUCT
	vkCode.l
	scanCode.l
	flags.l
	time.l
	dwExtraInfo.l
EndStructure 

Procedure KeyboardLLProc(nCode,wParam,*kbdhs.KBDLLHOOKSTRUCT)
	If nCode = #HC_ACTION And *kbdhs\vkCode >= #VK_F1 And *kbdhs\vkCode <= #VK_F12
		ProcedureReturn 1
	EndIf
	
	ProcedureReturn CallNextHookEx_(0,nCode,wParam,*kbdhs)
EndProcedure

hhkKeyboardLL = SetWindowsHookEx_(#WH_KEYBOARD_LL,@KeyboardLLProc(),GetModuleHandle_(0),0)

OpenWindow(0,0,0,320,240,"void",#WS_VISIBLE)

AddSysTrayIcon(0,WindowID(0),LoadImage(0,#PB_Compiler_Home + "Examples\Sources\Data\CdPlayer.ico"))

Repeat
	EventID = WaitWindowEvent()
	
	If EventID = #PB_Event_SysTray And  EventType() = #PB_EventType_RightClick
		CreatePopupMenu(0)
		MenuItem(0,"Exit Keyboard Hook")
		DisplayPopupMenu(0,WindowID(0))
	EndIf
	
	If EventID = #PB_Event_Menu
		UnhookWindowsHookEx_(hhkKeyboardLL) : End
	EndIf
ForEver
Windows 10 Pro, 64-Bit / Outtakes | Derek
Antworten