I found some great source code from a website (https://www.rondebruin.nl/win/s4/win012.htm) that enables you to disable the user's ability to use keyboard shortcuts. I've used the blocks of code that disable/enable all keyboard shortcuts — not just ones that are listed.
I'd like to adapt the code so that I can disable all keyboard shortcuts, but still list any exemptions at the bottom. For example, the following will block all attempted keyboard shortcuts, but how can I allow Ctrl + X, Ctrl + C, Ctrl + V, Alt + F8 and any others to be exempt?
I'd like to adapt the code so that I can disable all keyboard shortcuts, but still list any exemptions at the bottom. For example, the following will block all attempted keyboard shortcuts, but how can I allow Ctrl + X, Ctrl + C, Ctrl + V, Alt + F8 and any others to be exempt?
Code:
[/COLOR][COLOR=#3366CC]Sub Disable_Keys()[/COLOR]
Dim StartKeyCombination As Variant
Dim KeysArray As Variant
Dim Key As Variant
Dim I As Long
On Error Resume Next
[COLOR=black] 'Shift key = "+" (plus sign)
'Ctrl key = "^" (caret)
'Alt key = "%" (percent sign
'We fill the array with this keys and the key combinations
'Shift-Ctrl, Shift- Alt, Ctrl-Alt, Shift-Ctrl-Alt
[/COLOR]
For Each StartKeyCombination In Array("+", "^", "%", "+^", "+%", "^%", "+^%")
KeysArray = Array("{BS}", "{BREAK}", "{CAPSLOCK}", "{CLEAR}", "{DEL}", _
"{DOWN}", "{END}", "{ENTER}", "~", "{ESC}", "{HELP}", "{HOME}", _
"{INSERT}", "{LEFT}", "{NUMLOCK}", "{PGDN}", "{PGUP}", _
"{RETURN}", "{RIGHT}", "{SCROLLLOCK}", "{TAB}", "{UP}")
[COLOR=black] 'Disable the StartKeyCombination key(s) with every key in the KeysArray[/COLOR]
For Each Key In KeysArray
Application.OnKey StartKeyCombination & Key, ""
Next Key
[COLOR=black]'Disable the StartKeyCombination key(s) with every other key[/COLOR]
For I = 0 To 255
Application.OnKey StartKeyCombination & Chr$(I), ""
Next I
[COLOR=black]'Disable the F1 - F15 keys in combination with the Shift, Ctrl or Alt key[/COLOR]
For I = 1 To 15
Application.OnKey StartKeyCombination & "{F" & I & "}", ""
Next I
Next StartKeyCombination
[COLOR=black]'Disable the F1 - F15 keys[/COLOR]
For I = 1 To 15
Application.OnKey "{F" & I & "}", ""
Next I
[COLOR=black]'Disable the PGDN and PGUP keys[/COLOR]
Application.OnKey "{PGDN}", ""
Application.OnKey "{PGUP}", "" [COLOR=#3366CC]End Sub[/COLOR][COLOR=#333333]