Intercepter les raccourcis windows?
Intercepter les raccourcis windows?
Une nouvelle question débile pour les gens compétant ici:
Est il possible d'intercepter raccourcis clavier de Windows, du type Ctrl+Alt+Suppr ou Alt+Tab?
Est il possible d'intercepter raccourcis clavier de Windows, du type Ctrl+Alt+Suppr ou Alt+Tab?
-
- Messages : 471
- Inscription : dim. 23/déc./2007 18:10
on peut pas bloquer ctrl-alt-del, je crois...
pour le reste avec un hook de clavier :
pour le reste avec un hook de clavier :
Code : Tout sélectionner
Enumeration
#Window_0
EndEnumeration
Enumeration
#Button_0
EndEnumeration
;Bloquer ALT+TAB, ATL+ESC, et Windows-Keys
;Basé sur un code de DANILO
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_TAB) And (*p\flags & #LLKHF_ALTDOWN)) Or ((*p\vkCode = #VK_ESCAPE) And (*p\flags & #LLKHF_ALTDOWN)) Or ((*p\vkCode & #VK_ESCAPE) And (GetKeyState_(#VK_CONTROL) & $8000))
ProcedureReturn 1
;
ElseIf (*p\vkCode = #VK_LWIN) Or (*p\vkCode = #VK_RWIN)
ProcedureReturn 1
EndIf
EndIf
EndIf
ProcedureReturn CallNextHookEx_(0, nCode, wParam, lParam)
EndProcedure
;#WH_KEYBOARD_LL = 13
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 450, 200, 265, 186, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
ButtonGadget(#Button_0, 60, 40, 130, 35, "Bloquer !")
EndIf
EndProcedure
OpenWindow_Window_0()
;
Repeat
Select WaitWindowEvent()
; ///////////////////
Case #PB_Event_Gadget
Select EventGadget()
Case #Button_0
hook = SetWindowsHookEx_(#WH_KEYBOARD_LL,@myKeyboardHook(),GetModuleHandle_(0),0)
EndSelect
; ////////////////////////
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Window_0
UnhookWindowsHookEx_(hook)
CloseWindow(#Window_0)
Break
EndSelect
EndSelect
ForEver
Detecter CTRL ALT SUPPR c'est pas dur...
Libre a toi ensuite de "tuer" le taskmgr.exe dès qu'il apparait et de lancer une autre action à la place.
Pour Alt Tab c'est une autre paire de manche
Code : Tout sélectionner
Enumeration
#ARS : #info
EndEnumeration
If OpenWindow(#ARS, 456, 257, 279, 180, "Test", #PB_Window_SystemMenu | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(#ARS))
TextGadget(#info, 10, 160, 260, 20, "Essaye le CTRL gauche +ALT droit +SUPPR", #PB_Text_Center)
EndIf
EndIf
Repeat
InitKeyboard()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_RightAlt) And KeyboardPushed(#PB_Key_Delete)
MessageRequester("Bing :)","CTRL ALT SUP !")
End
EndIf
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case #ARS
CloseWindow(#ARS)
Break
EndSelect
EndSelect
ForEver
Pour Alt Tab c'est une autre paire de manche

~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Re: Intercepter les raccourcis windows?
Personnellement j'ai cette erreur sur le code :
En quoi l'écran a un role à jouer la dedans ?
Je suis perdu ...
Code : Tout sélectionner
[ERROR] OpenScreen() or OpenWindowScreen() must be call before using any keyboard command.
Je suis perdu ...
.:NY152:.
Re: Intercepter les raccourcis windows?
Sous winxp ça ouvre task manager, tu fais comme ça (merci droopy lib) :
Sous Seven faut faire autrement avec les solution du haut, mais pour kill le taskmanager c'est la même.
Sous Seven faut faire autrement avec les solution du haut, mais pour kill le taskmanager c'est la même.
Code : Tout sélectionner
ProcedureDLL KillProcess(Pid) ; Kill a process by specifying it's Pid
phandle = OpenProcess_ (#PROCESS_TERMINATE, #False, Pid)
If phandle <> #Null
If TerminateProcess_ (phandle, 1)
Result = #True
EndIf
CloseHandle_ (phandle)
EndIf
ProcedureReturn Result
EndProcedure
ProcedureDLL SearchProcess(Name.s) ; Search if a Process is Running ( Scans processes without Window(s) as well )
Name.s=UCase(Name.s)
Recherche=0
If OpenLibrary(0, "Kernel32.dll")
CreateToolhelpSnapshot = GetFunction(0, "CreateToolhelp32Snapshot")
ProcessFirst = GetFunction(0, "Process32First")
ProcessNext = GetFunction(0, "Process32Next")
If CreateToolhelpSnapshot And ProcessFirst And ProcessNext ; Ensure than all the functions are found
Process.PROCESSENTRY33\dwSize = SizeOf(PROCESSENTRY33)
Snapshot = CallFunctionFast(CreateToolhelpSnapshot, #TH32CS_SNAPPROCESS, 0)
If Snapshot
ProcessFound = CallFunctionFast(ProcessFirst, Snapshot, Process)
While ProcessFound
Nom.s=UCase(PeekS(@Process\szExeFile))
Nom=GetFilePart(Nom)
If Nom=Name : Recherche =1 : EndIf
ProcessFound = CallFunctionFast(ProcessNext, Snapshot, Process)
Wend
EndIf
CloseHandle_(Snapshot)
EndIf
CloseLibrary(0)
EndIf
ProcedureReturn Recherche
EndProcedure
ProcedureDLL GetPidProcess(Name.s) ; Returns Pid of Process if it exists / 0 if it doesn't exist
Name.s=UCase(Name.s)
Recherche=0
If OpenLibrary(0, "Kernel32.dll")
CreateToolhelpSnapshot = GetFunction(0, "CreateToolhelp32Snapshot")
ProcessFirst = GetFunction(0, "Process32First")
ProcessNext = GetFunction(0, "Process32Next")
If CreateToolhelpSnapshot And ProcessFirst And ProcessNext ; Ensure than all the functions are found
Process.PROCESSENTRY33\dwSize = SizeOf(PROCESSENTRY33)
Snapshot = CallFunctionFast(CreateToolhelpSnapshot, #TH32CS_SNAPPROCESS, 0)
If Snapshot
ProcessFound = CallFunctionFast(ProcessFirst, Snapshot, Process)
While ProcessFound
Nom.s=UCase(PeekS(@Process\szExeFile))
Nom=GetFilePart(Nom)
If Nom=Name
Recherche =1
Pid=Process\th32ProcessID
EndIf
ProcessFound = CallFunctionFast(ProcessNext, Snapshot, Process)
Wend
EndIf
CloseHandle_(Snapshot)
EndIf
CloseLibrary(0)
EndIf
ProcedureReturn Pid
EndProcedure
Repeat
If SearchProcess("taskmgr.exe")
KillProcess(GetPidProcess("taskmgr.exe"))
EndIf
ForEver
Modérateur
Config : Intel I5 4670K, Nvidia Geforce GTX 1060, 16go RAM, SSD 256go, DD 2000go
Config : Intel I5 4670K, Nvidia Geforce GTX 1060, 16go RAM, SSD 256go, DD 2000go
Re: Intercepter les raccourcis windows?
C'est pas ce que je demandais ...
Pas grave, je continue de chercher.
Pas grave, je continue de chercher.
.:NY152:.
Re: Intercepter les raccourcis windows?
Qestion :
Sans directX, on peut créer et donc intercepter les raccourcis avec :
AddKeyboardShortcut() (voir l'aide de PB)
Faisons un test.
Aïe...
Les raccourcis simples comme CTRL+F fonctionnent mais pas les raccourcis "systèmes" comme CTRL+ALT+DEL
Essayons la version avec DirectX
Aïe, ça ne marche pas non plus.
A priori, PB ne gère pas les raccourcis systèmes.
Il faut passer par l'api Windows et pour cela la version de démonstration de PB ne suffit pas, il faut acheter la licence.
Si c'est déjà le cas alors voyons ce que nous dit google.fr avec "purebasic Ctrl+Alt+"
Parmi les résultats se trouve en 1ère ligne :
http://www.purebasic.fr/english/viewtop ... f=5&t=5470
Le code date de 2003, mmmm...
Il faut l'adapter à PV4.xx
Ça marche ! le ctrl alt suppr est désactivé en utilisant un hook clavier.
Pour sortir de la fenêtre, taper 123.
Marche avec ALT+TAB, ATL+ESC, et Windows-Keys sous Windows XP.
A verifier sous W7.
En cherchant mieux, il existe peut-être une meilleure solution.
Mesa.
L'aide de purebasic (PB) nous donne 2 solutions : avec ou sans DirectX (Sous WIndows évidemment).Est il possible d'intercepter raccourcis clavier de Windows, du type Ctrl+Alt+Suppr ou Alt+Tab?
Sans directX, on peut créer et donc intercepter les raccourcis avec :
AddKeyboardShortcut() (voir l'aide de PB)
Faisons un test.
Code : Tout sélectionner
Enumeration ;fenêtre
#fenetre_0
EndEnumeration
Enumeration ;gadget
#EditorGadget_0
EndEnumeration
If OpenWindow(#fenetre_0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(#EditorGadget_0, 8, 8, 306, 133)
For a = 0 To 5
AddGadgetItem(#EditorGadget_0, a, "Ligne "+Str(a))
Next
;AddKeyboardShortcut(#Fenetre, Raccourci, Event)
AddKeyboardShortcut(#fenetre_0, #PB_Shortcut_Control | #PB_Shortcut_F, 1) ; Crée un raccourci clavier CTRL+F sur la fenêtre #fenetre_0
AddKeyboardShortcut(#fenetre_0, #PB_Shortcut_Control | #PB_Shortcut_Alt|#PB_Shortcut_Delete, 2) ; Crée un raccourci clavier CTRL+ALT+SUPPR sur la fenêtre #fenetre_0
AddKeyboardShortcut(#fenetre_0, #PB_Shortcut_Control | #PB_Shortcut_Alt, 3) ; Crée un raccourci clavier CTRL+ALT sur la fenêtre #fenetre_0
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #EditorGadget_0 : Debug "EditorGadget_0 cliqué!"
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case 1 : Debug "CTRL+F"
Case 2 : Debug "CTRL+ALT+SUPPR" ;ne fonctionne pas, il faut passer par l'api
Case 3 : Debug "CTRL+ALT";;ne fonctionne pas, il faut passer par l'api
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
;RemoveKeyboardShortcut(#fenetre_0, #PB_Shortcut_All )
Les raccourcis simples comme CTRL+F fonctionnent mais pas les raccourcis "systèmes" comme CTRL+ALT+DEL
Essayons la version avec DirectX
Code : Tout sélectionner
Enumeration
#ARS : #info
EndEnumeration
If InitSprite() = 0
MessageRequester("Erreur", "Impossible d'ouvrir l'écran & l'environnement nécessaire aux sprites !", 0)
End
EndIf
InitKeyboard()
If OpenWindow(#ARS, 456, 257, 279, 200, "Test", #PB_Window_SystemMenu | #PB_Window_TitleBar )
TextGadget(#info, 10, 160, 260, 50, "Essaye le CTRL gauche +ALT droit +SUPPR", #PB_Text_Center)
OpenWindowedScreen(WindowID(#ARS), 0, 0, 160, 160, 0, 0, 0)
EndIf
Repeat
ExamineKeyboard()
If KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_RightAlt) And KeyboardPushed(#PB_Key_Delete)
MessageRequester("Bing :)","CTRL ALT SUP !")
End
EndIf
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case #ARS
CloseWindow(#ARS)
Break
EndSelect
EndSelect
ForEver
A priori, PB ne gère pas les raccourcis systèmes.
Il faut passer par l'api Windows et pour cela la version de démonstration de PB ne suffit pas, il faut acheter la licence.
Si c'est déjà le cas alors voyons ce que nous dit google.fr avec "purebasic Ctrl+Alt+"
Parmi les résultats se trouve en 1ère ligne :
http://www.purebasic.fr/english/viewtop ... f=5&t=5470
Le code date de 2003, mmmm...
Il faut l'adapter à PV4.xx
Code : Tout sélectionner
;
; by Danilo, Posted - 26 Sep 2002 : 03:14:34 (engl. forum)
;
; merendo,
;
; on winNT/2000/XP no program is allowed To
; block the CTRL+ALT+DEL, because this would
; be a security risc.
; Every program could block CTRL+ALT+DEL And
; do what it wants... And the user couldnt stop
; it anymore.
;
; If you use Windows98, you can do it by telling
; windows your app is a screensaver.
;
; This code disables ALT+TAB, ATL+ESC, And Windows-Keys...
; ...also on Win2000:
; The line " SystemParametersInfo_( #SPI_SCREENSAVERRUNNING, 1, @Dummy, 0) "
; is For Windows 9x Systems.
; It tells Windows that a screensaver is running, so it blocks
; all other input on Win9x.
SystemParametersInfo_( #SPI_SCREENSAVERRUNNING, 1, @Dummy, 0);
OpenLibrary(1,"kernel32.dll")
CallFunction(1,"RegisterServiceProcess", GetCurrentProcessId_(), 1 )
Structure KBDLLHOOKSTRUCT
vkCode.l
scanCode.l
flags.l
time.l
dwExtraInfo.l
EndStructure
Global hook
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_TAB) And (*p\flags & #LLKHF_ALTDOWN)) Or ((*p\vkCode = #VK_ESCAPE) And (*p\flags & #LLKHF_ALTDOWN)) Or ((*p\vkCode & #VK_ESCAPE) And (GetKeyState_(#VK_CONTROL) & $8000)) ;Or
ProcedureReturn 1
ElseIf (*p\vkCode = #VK_LWIN) Or (*p\vkCode = #VK_RWIN)
ProcedureReturn 1
EndIf
EndIf
EndIf
;beep_(800,1)
ProcedureReturn CallNextHookEx_(hook, nCode, wParam, lParam)
EndProcedure
; Win NT
#WH_KEYBOARD_LL = 13
hook = SetWindowsHookEx_(#WH_KEYBOARD_LL,@myKeyboardHook(),GetModuleHandle_(0),0)
;If hook = 0: End: EndIf
hWnd = OpenWindow(1,10,10,100,100,"",#PB_Window_BorderLess)
ShowWindow_(hWnd, #SW_MAXIMIZE)
;SetWinBackgroundColor_(hWnd,0)
;CreateGadgetList(hWnd)
hString = StringGadget(1,GetSystemMetrics_(#SM_CXSCREEN)/2-100/2, GetSystemMetrics_(#SM_CYSCREEN)/2,100,20,"Enter Password",#PB_String_Numeric)
SetFocus_(hString)
GetWindowRect_(hString, winrect.RECT)
;SetThreadPriority_(GetCurrentThread_(),#REALTIME_PRIORITY_CLASS)
Repeat
Message = WindowEvent()
SetActiveWindow_(hWnd)
SetWindowPos_(hWnd,#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
ClipCursor_(winrect)
SendMessage_(hstring,#WM_KEYDOWN,#VK_END,0)
SetFocus_(hString)
If Message
Select Message
Case #PB_Event_Gadget
Select EventGadget()
Case 1
If GetGadgetText(1) = "123"
UnhookWindowsHookEx_(hook)
ClipCursor_(0)
SystemParametersInfo_( #SPI_SCREENSAVERRUNNING, 0, @Dummy, 0);
End
EndIf
EndSelect
EndSelect
Else
Delay(1)
EndIf
ForEver
; But CTRL+ALT+DEL can on win2000 only be disabled
; by writing a lowlevel system device driver For the keyboard.
; Info about this should be in the MS DDK.
;
; Best way For you would be To install win98
; on your disco machine...
;
; cya,
; ...Danilo
;
; (registered PureBasic user)
;
Pour sortir de la fenêtre, taper 123.
Marche avec ALT+TAB, ATL+ESC, et Windows-Keys sous Windows XP.
A verifier sous W7.
En cherchant mieux, il existe peut-être une meilleure solution.
Mesa.
Re: Intercepter les raccourcis windows?
Oui MAIS :
De vos codes, aucuns ne marche car personnellement j'ai cette erreur !NY152 a écrit :Personnellement j'ai cette erreur sur le code :
En quoi l'écran a un role à jouer la dedans ?Code : Tout sélectionner
[ERROR] OpenScreen() or OpenWindowScreen() must be call before using any keyboard command.
Je suis perdu ...
.:NY152:.
Re: Intercepter les raccourcis windows?
FAUX !
Tous mes codes fonctionnent (sous Xp 32bits).
J'ai modifié le code d'Ars pour ne plus avoir cette alerte.
Regarde bien
Vérifie avant s'il te plait.
Mesa.
Tous mes codes fonctionnent (sous Xp 32bits).
J'ai modifié le code d'Ars pour ne plus avoir cette alerte.
Regarde bien



Vérifie avant s'il te plait.
Mesa.
Re: Intercepter les raccourcis windows?
Tu veux que je te dise que ton code fonctionne ?
Collé tel quel, tu as ta fenêtre en plein écran où est indiqué "Enter password:" (jusque là normal) sauf que ton programme gèle là. Impossible de lui donner le password. Un petit ALT+CTRL+SUPPR et j'ai le menu Windows où la seule chose possible pour s'en sortir est une fermeture de session ; Alors non ton code ne fonctionne pas. Je suis sur Windows 7 64 bit.
Je cherchais juste un code me permettant d'intercepter une touche Fxx. Je préférerais passer par ExamineKeyboard() au lieux des API parce qu’apparemment d'une version de Windows à l'autre ça peut poser des problèmes.
Collé tel quel, tu as ta fenêtre en plein écran où est indiqué "Enter password:" (jusque là normal) sauf que ton programme gèle là. Impossible de lui donner le password. Un petit ALT+CTRL+SUPPR et j'ai le menu Windows où la seule chose possible pour s'en sortir est une fermeture de session ; Alors non ton code ne fonctionne pas. Je suis sur Windows 7 64 bit.
Je cherchais juste un code me permettant d'intercepter une touche Fxx. Je préférerais passer par ExamineKeyboard() au lieux des API parce qu’apparemment d'une version de Windows à l'autre ça peut poser des problèmes.
.:NY152:.
Re: Intercepter les raccourcis windows?
Salut.
Si tu souhaites seulement intercepter les touches Fxx ???
Pourquoi n'utilises tu pas AddKeyboardShortcut()
Regarde la fonction AddKeyboardShortcut() dans l'aide.
ça devrait correspondre à ta demande
Si tu souhaites seulement intercepter les touches Fxx ???
Pourquoi n'utilises tu pas AddKeyboardShortcut()
Regarde la fonction AddKeyboardShortcut() dans l'aide.
ça devrait correspondre à ta demande
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels