AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to detect if a particular mouse button is present?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Mistrel



Joined: 12 Sep 2005
Posts: 188

PostPosted: Thu Jul 12, 2007 12:16 am    Post subject: How to detect if a particular mouse button is present? Reply with quote

I want the script that I'm writing to be prepared for all possible mouse buttons 1, 2, 3, 4.. that might be available.

The problem I have is that if I run my script and the particular mouse button I wrote a hotkey for is not present AHK will report a message box with an error.

Is there a way to either suppress these errors or check to see if the key is present before assigning the hotkey?
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Thu Jul 12, 2007 12:22 am    Post subject: Reply with quote

perhaps you can use GetKeyState to see if its there. It should return blank for keys it can't get the state of.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
TeeTwo



Joined: 29 Dec 2006
Posts: 103
Location: Australia

PostPosted: Thu Jul 12, 2007 12:35 am    Post subject: Reply with quote

You could place an interogation of the mouse with a check for errorlevel
You could nest these checks to determine which mouse to support and then branch to that form
_________________
(The guy from Oz)
http:/InkMon.org
Inkmon4 & Inkmon5 for 4 and 5 colour printers
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2540
Location: Australia, Qld

PostPosted: Thu Jul 12, 2007 9:20 am    Post subject: Re: How to detect if a particular mouse button is present? Reply with quote

Kahz wrote:
The problem I have is that if I run my script and the particular mouse button I wrote a hotkey for is not present AHK will report a message box with an error.
Are you sure? My hotkey script uses XButton1 and XButton2 (among many others), and I have never had problems running it on systems that don't physically have these buttons. As long as you use the correct key/button names, you shouldn't get an error message. Although:
help: key list wrote:
Supported only in Windows 2000/XP or later:
XButton1 - a button that appears only on certain mice
XButton2 - a button that appears only on certain mice


engunneer, GetKeyState returns blank only if the keyname can't be associated with a virtual key code (i.e. it's invalid, or not a recognized key name.) XButton1 and 2 are defined in the AHK source code, so GetKeyState will return 0 when they aren't pressed, even if they don't physically exist on the mouse.

If you're interested, key names are mapped to virtual keycodes by using the array g_key_to_vk, which is initialized in globaldata.cpp (of the AHK source code.)

Code:
MsgBox, % "Your mouse has " . GetNumMouseButtons() . " buttons."

GetNumMouseButtons()
{
    static SM_CMOUSEBUTTONS = 43
    return DllCall("GetSystemMetrics", "int", SM_CMOUSEBUTTONS)
}
Adapted from a VB example. Smile
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Thu Jul 12, 2007 3:02 pm    Post subject: Reply with quote

thanks for the clarification. It makes sense. I wonder what error the OPP was getting?
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Superfraggle



Joined: 02 Nov 2004
Posts: 837
Location: London, UK

PostPosted: Thu Jul 12, 2007 3:09 pm    Post subject: Reply with quote

Running that code on my laptop produces 5 buttons, when I only have 3.

But I do have two mouse1's and two mouse2's which add up to five, but they are not 5 individual separate keys.
_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle
Back to top
View user's profile Send private message MSN Messenger
Lexikos



Joined: 17 Oct 2006
Posts: 2540
Location: Australia, Qld

PostPosted: Fri Jul 13, 2007 12:19 am    Post subject: Reply with quote

Superfraggle wrote:
Running that code on my laptop produces 5 buttons, when I only have 3.
I had a feeling that wouldn't work... oh well. I thought to try DirectInput, but that reports 7 mouse buttons for me. Mad
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 837
Location: London, UK

PostPosted: Fri Jul 13, 2007 12:54 am    Post subject: Reply with quote

how about the old fashioned way

Please press each button on the mouse now lol
_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group