|
-
Feb 18th, 2000, 07:51 PM
#1
Thread Starter
Junior Member
I am having major problems with my project at the moment. I have posted before, but I need a little more help.
What I need to do is detect when Ctrl Alt and Del are being pressed (Ctrl Alt Del is disable). I need to know this so that I can show a fake End Task dialogue.
I have the following code for detecting all three keys are pressed.
Option Explicit
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private mblnAltState As Boolean
Private mblnCtrlState As Boolean
Private mblnDelState As Boolean
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
mblnAltState = (Shift And vbAltMask)
mblnCtrlState = (Shift And vbCtrlMask)
If GetAsyncKeyState(vbKeyDelete) <> 0 Then
mblnDelState = True
Else
mblnDelState = False
End If
Update
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
mblnAltState = (Shift And vbAltMask)
mblnCtrlState = (Shift And vbCtrlMask)
mblnDelState = (vbKeyDelete)
If GetAsyncKeyState(vbKeyDelete) <> 0 Then
mblnDelState = True
Else
mblnDelState = False
End If
Update
End Sub
Private Function Update()
Cls
Print "Ctrl = "; mblnCtrlState
Print "Alt = "; mblnAltState
Print "Del = "; mblnDelState
If (mblnCtrlState = True) And (mblnAltState = True) Then
If GetAsyncKeyState(vbKeyDelete) <> 0 Then
MsgBox ("All three pressed!")
End If
End If
End Function
Private Sub Form_Load()
Me.KeyPreview = True
DisableCtrlAltDelete (True)
End Sub
Public Sub DisableCtrlAltDelete(bDisabled As Boolean)
Dim x As Long
x = SystemParametersInfo(97, bDisabled, CStr(1), 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
DisableCtrlAltDelete (False)
End Sub
The problem is when i press the crtl or alt keys first, then press Delete, the delete key doesn't register! But if I press Delete first, then Ctrl and Alt, I get all htree keys registering. I am puzzled .
Can anyone help me. I was wondering about setting up a hook or something for detecting the key presses. Can anyone shed any light on this?
Thanks
David Richardson 
-
Feb 19th, 2000, 01:16 AM
#2
Lively Member
Hmmm... What your doing sounds kinda sneaky, but it's for a good cause, right? Heh.
Anyway, there is a Windows API called GetKeyboardState that might help you out. I'm not entirely clear on its syntax, though.
-
Feb 24th, 2000, 12:13 AM
#3
Frenzied Member
Ctl-Alt-Del
You can catch the Ctl-Alt-Del sequence in Win95/98 by telling the OS that your app is a screen saver (these versions of windows allow password-protected screen savers, thus if your prog is a screen saver, Ctl-Alt-Del and Alt-Tab won't work to switch to another task). If you are running WinNT, I believe you're out of luck.
Here is the code and API call used to trap Ctl-Alt-Del is as follows (borrowed from James Limm)
Copy this code into the declarations section of a module:
Code:
Private Declare Function SystemParametersInfo Lib _
"user32" Alias "SystemParametersInfoA" (ByVal uAction _
As Long, ByVal uParam As Long, ByVal lpvParam As Any, _
ByVal fuWinIni As Long) As Long
Sub DisableCtrlAltDelete(bDisabled As Boolean)
Dim X As Long
X = SystemParametersInfo(97, bDisabled, CStr(1), 0)
End Sub
Then, in your code, to disable Ctrl-Alt-Delete:
Code:
Call DisableCtrlAltDelete(True)
To enable Ctrl-Alt-Delete:
Code:
Call DisableCtrlAltDelete(False)
Hope that helps
~seaweed
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|