+ Reply to Thread
Results 1 to 7 of 7

GetAsyncKeyState work rclick, not left

  1. #1
    Registered User
    Join Date
    02-08-2011
    Location
    Herndon, VA
    MS-Off Ver
    Office 2010
    Posts
    4

    GetAsyncKeyState work rclick, not left

    I am trying to trap a left mouse click. I've found code and it works for right click, but not left.

    I've defined the function and a worksheet_selectionchage function on a sheet i am testing

    This is in my main
    Please Login or Register  to view this content.
    This is on my sheet

    Please Login or Register  to view this content.
    When I right click, the msgbox fires. enter, arrow keys and other keys are trapped when I test, but not the stupid left mouse click
    TIA
    Rob

    Office 2010 x32, windows 7 x64

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: GetAsyncKeyState work rclick, not left

    Which version - your sig says 2010, your profile 2003?
    In 2007, that code gives me the Left button message for either mouse button.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    02-08-2011
    Location
    Herndon, VA
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: GetAsyncKeyState work rclick, not left

    I'll check my profile.
    I am using Office 2010 x32 and Windows 7 Enterprise x64

  4. #4
    Registered User
    Join Date
    02-08-2011
    Location
    Herndon, VA
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: GetAsyncKeyState work rclick, not left

    Sigh. The original code I found on the web tested right button first.
    the constants are correct, lbutton is 1 and rbutton is 2. Some uses and'ed h8000. Trying to pull a bit mask i guess. Whats frustrating is there are tons of examples using GetAsyncKeyState, some simple, some using different bit masks.
    I wouldnt think trapping the left mouse on a workheet SelectionChange would be so difficult.

  5. #5
    Registered User
    Join Date
    02-08-2011
    Location
    Herndon, VA
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: GetAsyncKeyState work rclick, not left

    Via news groups, I found something important and I dont understand what is going on:
    I was using
    Please Login or Register  to view this content.
    I got more success with
    Please Login or Register  to view this content.
    Now I find that on some of my sheets, the code will work, but on the sheet I need it, it wont.
    I was given this test code
    Please Login or Register  to view this content.
    On my "working" sheets all codes are trapped, on the sheet I need the left mouse key is not trapped.
    I'll update once I find out the cause...I hope is something stupid I am doing...it would be a lesson well learned.
    Last edited by rcamarda390; 02-09-2011 at 09:09 AM. Reason: clean up example code a bit

  6. #6
    Registered User
    Join Date
    01-19-2016
    Location
    INDIA
    MS-Off Ver
    KARNATAKA
    Posts
    1

    Re: GetAsyncKeyState work rclick, not left

    why this &H8000 is used

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: GetAsyncKeyState work rclick, not left

    Hello riyaj m,

    Welcome to the Forum!

    The last time this post was active was in 2011. In the future please start a new thread and reference the older thread.

    The reason is to check the MSB of the return value which is a Short Integer (16 bits). If the most significant bit is set, the key is down. However, this is not always reliable.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1