| View previous topic :: View next topic |
| Author |
Message |
Mistrel
Joined: 12 Sep 2005 Posts: 188
|
Posted: Thu Jul 12, 2007 12:16 am Post subject: How to detect if a particular mouse button is present? |
|
|
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 |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Thu Jul 12, 2007 12:22 am Post subject: |
|
|
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 |
|
 |
TeeTwo
Joined: 29 Dec 2006 Posts: 103 Location: Australia
|
Posted: Thu Jul 12, 2007 12:35 am Post subject: |
|
|
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 |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2540 Location: Australia, Qld
|
Posted: Thu Jul 12, 2007 9:20 am Post subject: Re: How to detect if a particular mouse button is present? |
|
|
| 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.  |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Thu Jul 12, 2007 3:02 pm Post subject: |
|
|
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 |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 837 Location: London, UK
|
Posted: Thu Jul 12, 2007 3:09 pm Post subject: |
|
|
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 |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2540 Location: Australia, Qld
|
Posted: Fri Jul 13, 2007 12:19 am Post subject: |
|
|
| 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.  |
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 837 Location: London, UK
|
Posted: Fri Jul 13, 2007 12:54 am Post subject: |
|
|
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 |
|
 |
|