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("AllowByPassKey") = 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("AllowByPassKey", _
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.
fmewAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BrianWrenCommented:
Do you mean that given a key status you want to put back the Shift key functionality, or do you mean to leave a 'backdoor' where a key status will allow those in th know to avoid the autoexec?

Brian
0
fmewAuthor Commented:
I suppose I want the Backdoor.
But can you explain the difference?
0
BrianWrenCommented:
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
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

fmewAuthor Commented:
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?
0
BrianWrenCommented:
Yeah.  Just disable the Shift key when you develop the db in the first place.

Till Thursday then...

Brian
0
fmewAuthor Commented:
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
0
BrianWrenCommented:
Erik,

When you select someone's Comment as an Answer, (there's a link at the top of each comment), then you grade the comment, and the points are awarded.

Are you saying that you can't get into your db at all?  You're essentially locked out by the AutoExec?

Brian
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fmewAuthor Commented:
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?
0
BrianWrenCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.