Globaler Keyboard Hook (Win32)
- NicTheQuick
- Ein Admin
- Beiträge: 8809
- Registriert: 29.08.2004 20:20
- Computerausstattung: Ryzen 7 5800X, 64 GB DDR4-3200
Ubuntu 24.04.2 LTS
GeForce RTX 3080 Ti - Wohnort: Saarbrücken
Sorry, Falschaussage: Auch unter DirectInput kann man einen Tastendruck simulieren...

Code: Alles auswählen
If *p\vkCode = #VK_LWIN
keybd_event_($4D, MapVirtualKey_($4D,0), 0, 0)
keybd_event_($4D, MapVirtualKey_($4D,0), #KEYEVENTF_KEYUP, 0)
ProcedureReturn 1
EndIf

Dazu eine Frage:
Wie kann ich denn in der oberen mykeyboardhook-procedure abfangen, wenn jemand z.b. STRG-V drückt?
Mit
If *p\vkCode = #VK_LCONTROL And *p\vkCode = #VK_V...
geht es jedenfalls nicht.
Kurz und gut: Wie soll das mit Tasten-Kombinationen funktionieren?
Wie kann ich denn in der oberen mykeyboardhook-procedure abfangen, wenn jemand z.b. STRG-V drückt?
Mit
If *p\vkCode = #VK_LCONTROL And *p\vkCode = #VK_V...
geht es jedenfalls nicht.
Kurz und gut: Wie soll das mit Tasten-Kombinationen funktionieren?
Agent_Sasori
It's not a bug - it's a feature!
http://www.StephenKalisch.de | http://www.ria-tec.com | http://www.dirsync.de
It's not a bug - it's a feature!
http://www.StephenKalisch.de | http://www.ria-tec.com | http://www.dirsync.de
Versuch mal:
Gruß
René
Code: Alles auswählen
If ((*p\vkCode = #VK_V) And (GetKeyState_(#VK_CONTROL) & $8000))
...
René
Hm...
für was ist denn die $8000???? (hex ist klar, aber 8000)
für was ist denn die $8000???? (hex ist klar, aber 8000)
Agent_Sasori
It's not a bug - it's a feature!
http://www.StephenKalisch.de | http://www.ria-tec.com | http://www.dirsync.de
It's not a bug - it's a feature!
http://www.StephenKalisch.de | http://www.ria-tec.com | http://www.dirsync.de
ah....
noch gedrückt.... kann das sein?
noch gedrückt.... kann das sein?
Agent_Sasori
It's not a bug - it's a feature!
http://www.StephenKalisch.de | http://www.ria-tec.com | http://www.dirsync.de
It's not a bug - it's a feature!
http://www.StephenKalisch.de | http://www.ria-tec.com | http://www.dirsync.de
*buddel* *ausgrab*
warum spert mein Code nicht F1 bis F12???
Edit: Warum verlangsamt mein Code auch noch die Tasta?
gibt es überhaupt eine möglichkeit es elegant ohne fenster zu lösen?
warum spert mein Code nicht F1 bis F12???
Code: Alles auswählen
; by Danilo, 07.04.2003 - german forum
;
Global hWindow,msg,hook
Structure KBDLLHOOKSTRUCT
vkCode.l
scanCode.l
flags.l
time.l
dwExtraInfo.l
EndStructure
Procedure.l myKeyboardHook(nCode, wParam, *p.KBDLLHOOKSTRUCT)
If nCode = #HC_ACTION
If wParam = #WM_KEYDOWN Or wParam = #WM_SYSKEYDOWN Or wParam = #WM_KEYUP Or wParam = #WM_SYSKEYUP
#LLKHF_ALTDOWN = $20
If *p\vkCode => #VK_F1 And *p\vkCode <= #VK_F12 ; F1 - F12 sperren!!
If *p\vkCode = #VK_F12
msg = 1
EndIf
ProcedureReturn 1
EndIf
EndIf
EndIf
ProcedureReturn CallNextHookEx_(0, nCode, wParam, *p)
EndProcedure
Procedure AskForExit()
If MessageRequester("EXIT", "End the KeyboardHook ??",#MB_YESNO) = #IDYES
UnhookWindowsHookEx_(hook) : End
EndIf
EndProcedure
; Win NT
#WH_KEYBOARD_LL = 13
hook = SetWindowsHookEx_(#WH_KEYBOARD_LL,@myKeyboardHook(),GetModuleHandle_(0),0)
If hook = 0: End: EndIf
Repeat
If msg = 1
MessageRequester("lol","geht ned")
AskForExit()
msg = 0
EndIf
ForEver
gibt es überhaupt eine möglichkeit es elegant ohne fenster zu lösen?
- Fluid Byte
- Beiträge: 3110
- Registriert: 27.09.2006 22:06
- Wohnort: Berlin, Mitte
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