fmew
asked on
DisableShortcutKey
I used this module to disable the Shift shortcutkey in a copy of my application:
-------------------------- -----
Function faq_DisableShiftKeyBypass( ) As Boolean
'The next time the database is opened
' after this function has been run,
' the autoexec macro will not be bypassed,
' even if the shift key is pressed.
On Error GoTo errDisableShift
Dim DB As DATABASE
Dim prop As Property
Const conPropNotFound = 3270
Set DB = CurrentDb()
DB.Properties("AllowByPass Key") = True
faq_DisableShiftKeyBypass = True
exitDisableShift:
Exit Function
errDisableShift:
'The AllowBypassKey property is a user-defined
' property of the database that must be created
' before it can be set. This error code will execute
' the first time this function is run in a database.
If Err = conPropNotFound Then
Set prop = DB.CreateProperty("AllowBy PassKey", _
dbBoolean, False)
DB.Properties.Append prop
Resume Next
Else
MsgBox "Function DisableShiftKeyBypass did" & _
" not complete successfully."
faq_DisableShiftKeyBypass = False
GoTo exitDisableShift
End If
End Function
-------------------------- ----------
Is there a way to change this module? I want to enable the shortcutkey with 2 or more other keys.
--------------------------
Function faq_DisableShiftKeyBypass(
'The next time the database is opened
' after this function has been run,
' the autoexec macro will not be bypassed,
' even if the shift key is pressed.
On Error GoTo errDisableShift
Dim DB As DATABASE
Dim prop As Property
Const conPropNotFound = 3270
Set DB = CurrentDb()
DB.Properties("AllowByPass
faq_DisableShiftKeyBypass = True
exitDisableShift:
Exit Function
errDisableShift:
'The AllowBypassKey property is a user-defined
' property of the database that must be created
' before it can be set. This error code will execute
' the first time this function is run in a database.
If Err = conPropNotFound Then
Set prop = DB.CreateProperty("AllowBy
dbBoolean, False)
DB.Properties.Append prop
Resume Next
Else
MsgBox "Function DisableShiftKeyBypass did" & _
" not complete successfully."
faq_DisableShiftKeyBypass = False
GoTo exitDisableShift
End If
End Function
--------------------------
Is there a way to change this module? I want to enable the shortcutkey with 2 or more other keys.
ASKER
I suppose I want the Backdoor.
But can you explain the difference?
But can you explain the difference?
The 1st modifies how the shift key will be handled the next time the app is opened. The other is an on-going capability.
I would, in the AutoExec macro, look at the state of the keys.
Use a User-defined function which returns true or false depending on the keys.
-------------------------- ---------- ---------- ---------- ---------- ---------- --------
Option Compare Database
Option Explicit
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
-------------------------- ---------- ---------- ---------- -----
Function KeyState() As Byte
' 1: Shft Key is down _
2: Ctrl Key is down _
4: Alt Key is down
KeyState = -1 * (GetAsyncKeyState(16) <> 0) _
+ -2 * (GetAsyncKeyState(17) <> 0) _
+ -4 * (GetAsyncKeyState(18) <> 0)
End Function
-------------------------- ---------- ---------- ---------- ------
Public Function BackDoor() As Boolean
BackDoor = (KeyState() = 6) ' Alt + Ctrl
End Function
-------------------------- ---------- ---------- ---------- ------
AutoExec:
Condition Action
BackDoor = True StopMacro
Brian
I would, in the AutoExec macro, look at the state of the keys.
Use a User-defined function which returns true or false depending on the keys.
--------------------------
Option Compare Database
Option Explicit
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
--------------------------
Function KeyState() As Byte
' 1: Shft Key is down _
2: Ctrl Key is down _
4: Alt Key is down
KeyState = -1 * (GetAsyncKeyState(16) <> 0) _
+ -2 * (GetAsyncKeyState(17) <> 0) _
+ -4 * (GetAsyncKeyState(18) <> 0)
End Function
--------------------------
Public Function BackDoor() As Boolean
BackDoor = (KeyState() = 6) ' Alt + Ctrl
End Function
--------------------------
AutoExec:
Condition Action
BackDoor = True StopMacro
Brian
ASKER
I have to evalute this thursday
Does this mean I dont need the module I put in my question?
And do I put all your code in 1 module?
How do I look/put the state of a key in an autoexec macro?
And can you tell someting about a User-defined function which returns true or false depending on the keys?
Does this mean I dont need the module I put in my question?
And do I put all your code in 1 module?
How do I look/put the state of a key in an autoexec macro?
And can you tell someting about a User-defined function which returns true or false depending on the keys?
Yeah. Just disable the Shift key when you develop the db in the first place.
Till Thursday then...
Brian
Till Thursday then...
Brian
ASKER
Hi Brian,
I was to busy, couldnt react on thursday
Just tried your module.
I dont know how to let it work. You set just disable the shift key in the first place. But I cant get in my db anymore. I did this: I Put my module in the autoexec as second (faq_DisableShiftKeyBypass ()). The first action then is: Backdoor() = true
Condition =Stop Macro
But I cant get in my db then.
I need some specific help Brian.
And what about:
I would, in the AutoExec macro, look at the state of the keys.
Use a User-defined function which returns true or false depending on the keys.
Can you help me with that
Last thing.
How do I give you your points, or goes that automaticly now?
Erik
I was to busy, couldnt react on thursday
Just tried your module.
I dont know how to let it work. You set just disable the shift key in the first place. But I cant get in my db anymore. I did this: I Put my module in the autoexec as second (faq_DisableShiftKeyBypass
Condition =Stop Macro
But I cant get in my db then.
I need some specific help Brian.
And what about:
I would, in the AutoExec macro, look at the state of the keys.
Use a User-defined function which returns true or false depending on the keys.
Can you help me with that
Last thing.
How do I give you your points, or goes that automaticly now?
Erik
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Brian
I tried this on a copy of my application.
I am looking for the right way to solve this thing.
So basicly, I have this module I send with my question. Do I still use that with your answer?
And how does your module fit in?
Do I put your module in one module?
And what about state of keeys
And
User Defined function?
I tried this on a copy of my application.
I am looking for the right way to solve this thing.
So basicly, I have this module I send with my question. Do I still use that with your answer?
And how does your module fit in?
Do I put your module in one module?
And what about state of keeys
And
User Defined function?
You put the
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
-------------------------- ---------- ---------- ---------- -----
Function KeyState() As Byte
' 1: Shft Key is down _
2: Ctrl Key is down _
4: Alt Key is down
KeyState = -1 * (GetAsyncKeyState(16) <> 0) _
+ -2 * (GetAsyncKeyState(17) <> 0) _
+ -4 * (GetAsyncKeyState(18) <> 0)
End Function
-------------------------- ---------- ---------- ---------- ------
Public Function BackDoor() As Boolean
BackDoor = (KeyState() = 6) ' Alt + Ctrl
End Function
all in a module.
Whenever the function BackDoor is run, it will use the KeyState() function, (which in turn will use the GetAsyncKeyState() API function), to read the current state of the keyboard.
If KeyState returns a 6, meaning that the Ctl and Alt keys are currently depressed, then the Backdoor function will return a True.
This can be utilised in a macro to either stop the macro, or alternately can be used to permit operations within the macro.
If you put in the conditions column:
BackDoor() = True
then the action on that row will happen if the Ctl and Alt keys are down when the macro runs.
If you put instead:
BackDoor() = False
then that row will run unlessthe Ctrl and Alt keys are down at the time the macro hits that line.
You can include several lines for one test in the conditions column by putting:
...
as the condition on lines immediately folowing the line with the test.
If you put as a condition, "BackDoor()=True", and made the action of that line "StopMacro", the macro would stop there. If that line were the first line of the macro, prior to hiding the Database window, prior to turning off menus, etc., then it would effectively let you 'get into' your DB, halting its startup procedures that you have programmed in.
Brian
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
--------------------------
Function KeyState() As Byte
' 1: Shft Key is down _
2: Ctrl Key is down _
4: Alt Key is down
KeyState = -1 * (GetAsyncKeyState(16) <> 0) _
+ -2 * (GetAsyncKeyState(17) <> 0) _
+ -4 * (GetAsyncKeyState(18) <> 0)
End Function
--------------------------
Public Function BackDoor() As Boolean
BackDoor = (KeyState() = 6) ' Alt + Ctrl
End Function
all in a module.
Whenever the function BackDoor is run, it will use the KeyState() function, (which in turn will use the GetAsyncKeyState() API function), to read the current state of the keyboard.
If KeyState returns a 6, meaning that the Ctl and Alt keys are currently depressed, then the Backdoor function will return a True.
This can be utilised in a macro to either stop the macro, or alternately can be used to permit operations within the macro.
If you put in the conditions column:
BackDoor() = True
then the action on that row will happen if the Ctl and Alt keys are down when the macro runs.
If you put instead:
BackDoor() = False
then that row will run unlessthe Ctrl and Alt keys are down at the time the macro hits that line.
You can include several lines for one test in the conditions column by putting:
...
as the condition on lines immediately folowing the line with the test.
If you put as a condition, "BackDoor()=True", and made the action of that line "StopMacro", the macro would stop there. If that line were the first line of the macro, prior to hiding the Database window, prior to turning off menus, etc., then it would effectively let you 'get into' your DB, halting its startup procedures that you have programmed in.
Brian
Brian