In user defined Hotkey, PC registers 'Shift' as 'Alt' and vice versa

Posted on 2003-03-16
Medium Priority
Last Modified: 2010-05-01

I Have set up a form to allow users to define and assign hotkeys for my application. It works, but I'm getting strange behaviour with the hotkey control in the following case:

If user selects Cntrl + a key as the hotkey, then the hotkey is correctly registered ie, when user presses Cntrl + a key after assigning, the hotkey is triggered.

HOWEVER, if user selects Alt + a key as the hotkey, pressing Alt + a key does nothing, but pressing Shift + a key works! Similarly, if user selects Shift + a key as the hotkey, pressing Shift + a key does nothing, but pressing Alt + a key works.

I believe I have correctly set up the constants properly as below:

Cntrl = 2
Shift = 4
Alt = 1

Why is the recognition of Alt and Shift being reversed by the system?? Does anyone know what's going on here and how to rectify it?


Question by:DoctorNash
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 11

Expert Comment

ID: 8149659
Private Const MOD_SHIFT = &H4
Private Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2

Private Function RegisterKey(keycode As Integer, shift As Integer) as Integer
    Dim ShiftKeys as Integer

    ShiftKeys = 0;
    if ((shift And vbShiftMask) <> 0) then ' Shift key is pressed
         ShiftKeys = ShiftKeys Or MOD_SHIFT
    End If
    if ((shift And VbCtrlMask) <> 0) then ' Ctrl key is pressed
         ShiftKeys = ShiftKeys Or MOD_CONTROL
    End If
    if ((shift And VbAltMask) <> 0) then ' Alt key is pressed
         ShiftKeys = ShiftKeys Or MOD_ALT
    End If

    RegisterKey = RegisterHotKey(Me.hwnd, 2, ShiftKeys, KeyCode)
End Sub

Good Luck!
LVL 11

Accepted Solution

supunr earned 75 total points
ID: 8149665
yes, you are right.  alt and shift key values should be reversed....use the code similar to above.

Expert Comment

ID: 8900021
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?

Author Comment

ID: 8905121
The basis of the code presented by supunr is sound.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question