| View previous topic :: View next topic |
| Author |
Message |
evl
Joined: 24 Aug 2005 Posts: 1239
|
Posted: Thu Mar 30, 2006 10:33 pm Post subject: USB device connected/disconnected notification? |
|
|
Does Windows broadcast a message to all processes when a usb device is plugged in/removed so that a script could just use OnMessage() to catch this (and then perform a check) instead of using a timer to constantly check?
The device in question is a usb microphone ("usb audio" device) so maybe it's different to detecting usb drives.
I've seen this thread (and replied about where I found device info is stored in the registry, in case it helps anyone else):
http://www.autohotkey.com/forum/viewtopic.php?t=6618
(a timer can be used to check this location quite well, but I'd prefer not to check the registry every second - 86400 times a day ) - plus it'd react faster to a message than a timer. |
|
| Back to top |
|
 |
Paulo Guest
|
Posted: Fri Mar 31, 2006 1:41 pm Post subject: |
|
|
I don't know for sure if it will work with mics but it works with all my usb devices.
OnMessage(0x219, "notify_change")
Return
notify_change(wParam, lParam, msg, hwnd)
{
MsgBox, %wParam% %lParam% %msg% %hwnd%
} |
|
| Back to top |
|
 |
Kevin4875
Joined: 21 Mar 2006 Posts: 5
|
Posted: Fri Mar 31, 2006 2:08 pm Post subject: |
|
|
Wow, how did you've done that?
It works with me too! |
|
| Back to top |
|
 |
evl
Joined: 24 Aug 2005 Posts: 1239
|
|
| Back to top |
|
 |
Goodhue Guest
|
Posted: Fri Mar 31, 2006 6:13 pm Post subject: |
|
|
| What about firewire devices? Is there a different message to use? |
|
| Back to top |
|
 |
evl
Joined: 24 Aug 2005 Posts: 1239
|
Posted: Fri Mar 31, 2006 6:39 pm Post subject: |
|
|
It probably works too:
| Quote: | | The WM_DEVICECHANGE device message notifies an application of a change to the hardware configuration of a device or the computer. |
Give it a try  |
|
| Back to top |
|
 |
evl
Joined: 24 Aug 2005 Posts: 1239
|
Posted: Fri Mar 31, 2006 6:43 pm Post subject: |
|
|
Also, the wParam value I get is not mentioned on the MSDN page:
0x0007 = DBT_DEVNODES_CHANGED
It was defined in the Dbt.h file (as mentioned on the site) which contains quite a bit of info. |
|
| Back to top |
|
 |
Tekl
Joined: 24 Sep 2004 Posts: 813 Location: Germany
|
Posted: Wed Jul 19, 2006 9:17 am Post subject: |
|
|
Hmmm... it seems not always to work with multi card readers when I plug in or remove media cards. Sometimes I'll get a message and sometimes not. _________________ Tekl |
|
| Back to top |
|
 |
Geek10000
Joined: 03 Feb 2008 Posts: 5
|
Posted: Sun Feb 10, 2008 7:54 am Post subject: How to detect if monitor is present |
|
|
| Hi. Thak you for the easy oode. I have laptop computer which I use partly at work, partly at home. When I am at home, I use it with an external monitor. Is there anyway to write a scrip that detect if there is a vga cable present in the slot - so that my laptop will change to external output when I connect it at home? Now I have to connect it, wait for half a minute, then press ctrl + alt + f1. Would be brilliant, but I dont know where to start. I have benne searching all the internet without any answears. Thank you in advance. Best. |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1484
|
Posted: Sun Feb 10, 2008 9:23 am Post subject: |
|
|
| Robin wrote: | | Holy Bumpzilla, Batman! |
I believe you may be interested in SysGet, outputvar, MonitorCount.
i.e.: | Code: | SysGet, HowMany, MonitorCount
msgfb := "There " ((HowMany-1) ? "are" : "is") " currently " HowMany
. " monitor" ((HowMany-1) ? "s" : "") " connected to your system."
msgbox % msgfb
return |
_________________ My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags ! |
|
| Back to top |
|
 |
Geek10000
Joined: 03 Feb 2008 Posts: 5
|
Posted: Sun Feb 10, 2008 4:35 pm Post subject: Detect VGA immeadtely |
|
|
Thank you so much. But is it possible to have this code to autmatically detect WHEN I plug in my external screen? So that the computer will send the keystrokes alt + ctrl + F1?
Thank you so much. |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1484
|
Posted: Wed Feb 13, 2008 4:37 am Post subject: |
|
|
| Code: | SetTimer, CheckForTwoMonitors, 400
CheckForTwoMonitors:
SysGet, HowMany, MonitorCount
If HowMany = %PrevMany%
return
If (( PrevMany := HowMany ) = 2)
Send ^!{F1}
return | How 'bout that? _________________ My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags ! |
|
| Back to top |
|
 |
Geek10000
Joined: 03 Feb 2008 Posts: 5
|
Posted: Wed Feb 13, 2008 1:05 pm Post subject: Detect monitors |
|
|
| Thank you! I will check as soon as I get home. But when I run this code on my laptop, the messagebox always tells me it is 1 monitor connected. Even if I have plugged in my external monitor in the vga-slot? |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1484
|
Posted: Wed Feb 13, 2008 8:17 pm Post subject: |
|
|
You need to have the second monitor enabled in your display properties for it to work properly. Otherwise I don't think AHK can detect a monitor being plugged in. _________________ My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags ! |
|
| Back to top |
|
 |
M3CSL
Joined: 21 Jan 2008 Posts: 35 Location: Germany
|
Posted: Wed Feb 13, 2008 11:43 pm Post subject: |
|
|
| Paulo wrote: | OnMessage(0x219, "notify_change")
Return
notify_change(wParam, lParam, msg, hwnd)
{
MsgBox, %wParam% %lParam% %msg% %hwnd%
} |
Is it possible to get the drive letter of the new device and open its content in Windows Explorer? |
|
| Back to top |
|
 |
|