View Full Version : Disable CTRL + '


shadow9449
12-07-2008, 11:23 AM
It's fairly easy to use Autokeys to trap keyboard combinations such as CTRL + P and the like to prevent mishaps. For some reason the Autokeys macro won't allow me to reassign CTRL + ' which repeats data from the corresponding field in the previous record. I have a user who accidentally hits that a lot (somehow) and I want to disable it. Does anyone know why the macro won't allow it or if there is another way to do it?

I'll point out that the Keypress event can trap only one keystroke at a time. I don't have any way for it to prevent combinations. I don't want to disable CTRL nor '.

SHADOW

Guus2005
12-07-2008, 11:55 PM
I don't have a solution.

But this is what i tried. It doesn't seem to work. I tried KeyDown and KeyPressed.


Declare Function wu_GetKeyState Lib "user32" Alias "GetKeyState" (ByVal VirtKey As Long) As Integer

Global Const vk_Shift = 16 ' Catch shift
Global Const vk_Control = 17 ' Catch control
Global Const vk_Alt = 18 ' Catch alt

Public Function ControlPressed()
ControlPressed = wu_GetKeyState(vk_Control) < 0
End Function

Private Sub txtSearchString_KeyDown(KeyCode As Integer, Shift As Integer)
If ControlPressed Then
If KeyAscii = Asc("+") Then
MsgBox "Control + pressed."
End If
End If
End Sub

Private Sub txtSearchString_KeyPress(KeyAscii As Integer)
If ControlPressed Then
If KeyAscii = Asc("+") Then
MsgBox "Control + pressed."
End If
End If
End Sub

Perhaps this might trigger somebody??

HTH:D

shadow9449
12-08-2008, 12:38 PM
Hi Guus

Actually, someone in another thread had a great idea. The idea was to capture the value of the shift code that's passed to the function. His example was with Alt but I was easily able to discover the value for CTRL.

Here's the code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = 2 Then
Select Case KeyCode
Case 222
KeyCode = 0
End Select
End If
End Sub

Maybe this will help somoene.

Thank you for your suggestion!

SHADOW