| 
		
	
	
	
		
	Posts: 5Threads: 2
 Joined: Apr 2007
 
	
	
		I have two mice connected to my PC and i currently use keyboard detector. I was wondering how to have a trigger where my mouse moves up, but only if its done by the second mouse, and the system volume should increase as the mouse moves up. Also the opposite for the mouse moving down. Thank you.
	 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		This macro sets audio volume depending on where you right click. Or right click and drag up or down. 
Assuming that your mouse that you'll use to set volume is associated with filter function FF_Mouse2.
 
Note that keyboard/mouse detector does not work if you are using low level hooks. Turn off LL hooks in Options -> Triggers.
 
Macro  
Trigger #R 0x8 //FF_Mouse2   double sch=ScreenHeight-1rep
 ,double v=(sch-ym)/sch*1.0
 ,;out v
 ,SetAudioVolume v
 ,ifk-((2)) break
 ,0.1
Also create this function: 
Function SetAudioVolume ;/function ^v ;;v must be between 0 and 1
 
 ;Sets audio output master volume.
 
 
 ;these declarations extracted from WINAPI2 reference file which is available in qm forum -> resources
 interface# IMMDeviceCollection :IUnknown
 ,GetCount(*pcDevices)
 ,Item(nDevice IMMDevice*ppDevice)
 ,{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}
 interface# IMMNotificationClient :IUnknown
 ,OnDeviceStateChanged(@*pwstrDeviceId dwNewState)
 ,OnDeviceAdded(@*pwstrDeviceId)
 ,OnDeviceRemoved(@*pwstrDeviceId)
 ,OnDefaultDeviceChanged(flow role @*pwstrDefaultDeviceId)
 ,OnPropertyValueChanged(@*pwstrDeviceId PROPERTYKEY'key)
 ,{7991EEC9-7E89-4D85-8390-6C703CEC60C0}
 type AUDIO_VOLUME_NOTIFICATION_DATA GUID'guidEventContext bMuted FLOAT'fMasterVolume nChannels FLOAT'afChannelVolumes[1]
 interface# IAudioEndpointVolumeCallback :IUnknown
 ,OnNotify(AUDIO_VOLUME_NOTIFICATION_DATA*pNotify)
 ,{657804FA-D6AD-4496-8A60-352752AF4F89}
 interface# IMMDevice :IUnknown
 ,Activate(GUID*iid dwClsCtx PROPVARIANT*pActivationParams !**ppInterface)
 ,OpenPropertyStore(stgmAccess IPropertyStore*ppProperties)
 ,GetId(@**ppstrId)
 ,GetState(*pdwState)
 ,{D666063F-1587-4E43-81F1-B948E807363F}
 interface# IAudioEndpointVolume :IUnknown
 ,RegisterControlChangeNotify(IAudioEndpointVolumeCallback'pNotify)
 ,UnregisterControlChangeNotify(IAudioEndpointVolumeCallback'pNotify)
 ,GetChannelCount(*pnChannelCount)
 ,SetMasterVolumeLevel(FLOAT'fLevelDB GUID*pguidEventContext)
 ,SetMasterVolumeLevelScalar(FLOAT'fLevel GUID*pguidEventContext)
 ,GetMasterVolumeLevel(FLOAT*pfLevelDB)
 ,GetMasterVolumeLevelScalar(FLOAT*pfLevel)
 ,SetChannelVolumeLevel(nChannel FLOAT'fLevelDB GUID*pguidEventContext)
 ,SetChannelVolumeLevelScalar(nChannel FLOAT'fLevel GUID*pguidEventContext)
 ,GetChannelVolumeLevel(nChannel FLOAT*pfLevelDB)
 ,GetChannelVolumeLevelScalar(nChannel FLOAT*pfLevel)
 ,SetMute(bMute GUID*pguidEventContext)
 ,GetMute(*pbMute)
 ,GetVolumeStepInfo(*pnStep *pnStepCount)
 ,VolumeStepUp(GUID*pguidEventContext)
 ,VolumeStepDown(GUID*pguidEventContext)
 ,QueryHardwareSupport(*pdwHardwareSupportMask)
 ,GetVolumeRange(FLOAT*pflVolumeMindB FLOAT*pflVolumeMaxdB FLOAT*pflVolumeIncrementdB)
 ,{5CDF2C82-841E-4546-9722-0CF74078229A}
 interface# IMMDeviceEnumerator :IUnknown
 ,EnumAudioEndpoints(dataFlow dwStateMask IMMDeviceCollection*ppDevices)
 ,GetDefaultAudioEndpoint(dataFlow role IMMDevice*ppEndpoint)
 ,GetDevice(@*pwstrId IMMDevice*ppDevice)
 ,RegisterEndpointNotificationCallback(IMMNotificationClient'pClient)
 ,UnregisterEndpointNotificationCallback(IMMNotificationClient'pClient)
 ,{A95664D2-9614-4F35-A746-DE8DB63617E6}
 def CLSID_MMDeviceEnumerator uuidof("{BCDE0395-E52F-467C-8E3D-C4579291692E}")
 def eRender 0
 def eMultimedia 0x00000001
 
 
 if(v<0 or v>1) end ES_BADARG
 if(_winnt>=6)
 ,IMMDeviceEnumerator en
 ,IMMDevice de
 ,IAudioEndpointVolume av
 ,en._create(CLSID_MMDeviceEnumerator)
 ,en.GetDefaultAudioEndpoint(eRender eMultimedia &de)
 ,de.Activate(uuidof(IAudioEndpointVolume) CLSCTX_ALL 0 &av)
 ,av.SetMasterVolumeLevelScalar(v 0)
 ,err+ ret
 else
 ,int vi=(v*0x4000)+(pow(v 4)*0xBFFF)
 ,;out vi
 ,;waveOutSetVolume(0 vi<<16|vi)
 ,
 ,if(!mixerGetNumDevs) ret
 ,
 ,;get volume control id
 ,MIXERLINE mxl.cbStruct=sizeof(mxl)
 ,mxl.dwComponentType=MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
 ,if(mixerGetLineInfo(0 &mxl MIXER_OBJECTF_MIXER|MIXER_GETLINEINFOF_COMPONENTTYPE)) ret
 ,MIXERCONTROL mxc
 ,MIXERLINECONTROLS mxlc.cbStruct=sizeof(mxlc)
 ,mxlc.dwLineID=mxl.dwLineID
 ,mxlc.dwControlType=MIXERCONTROL_CONTROLTYPE_VOLUME
 ,mxlc.cControls=1
 ,mxlc.cbmxctrl=sizeof(MIXERCONTROL)
 ,mxlc.pamxctrl=&mxc
 ,if(mixerGetLineControls(0 &mxlc MIXER_OBJECTF_MIXER|MIXER_GETLINECONTROLSF_ONEBYTYPE)) ret
 ,
 ,;set volume
 ,MIXERCONTROLDETAILS mxcd.cbStruct=sizeof(mxcd)
 ,mxcd.dwControlID=mxc.dwControlID
 ,mxcd.cChannels=1
 ,mxcd.cbDetails=sizeof(int)
 ,mxcd.paDetails=&vi
 ,if(mixerSetControlDetails(0 &mxcd MIXER_OBJECTF_MIXER|MIXER_SETCONTROLDETAILSF_VALUE)) ret
 ret 1
 
	
	
	
		
	Posts: 5Threads: 2
 Joined: Apr 2007
 
	
	
		wow, thank you. Is it possible to do this without clicking and also not depending where the mouse is but just if its moved up or down? i was thinking to have it push the VK_Volume_Up button whenever you move it.
	 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		QM mouse movement triggers also work with mouse detector, but you would have to move mouse eg up-down, and each time change volume eg by 10% or with the volume keys.
	 
	
	
	
		
	Posts: 5Threads: 2
 Joined: Apr 2007
 
	
	
		thats how i have it set up right now. my question was could the trigger be to simply have the mouse moving up be a detector
	 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		Edit Keyboard_Detector: 
find: 
Function Keyboard_Detector 
insert after: 
Function Keyboard_Detector ,,;out "%i %i %i" k raw.mouse.lLastX raw.mouse.lLastY,,if(k=g_rir.m[1])
 ,,,if(raw.mouse.lLastY>0) key (VK_VOLUME_DOWN)
 ,,,else if(raw.mouse.lLastY<0) key (VK_VOLUME_UP)
g_rir.m[1] is identifier of the mouse that is associated with the second filter function. For other mouses it is g_rir.m[0], g_rir.m[2], g_rir.m[3].
	 
	
	
	
		
	Posts: 5Threads: 2
 Joined: Apr 2007
 
	
	
		Thank you so much for all your help. This works perfectly.    
	
	
	
		
	Posts: 1,000Threads: 253
 Joined: Feb 2008
 
	
	
		I've been trying to get this to work.
 On a computer that has one sound card I can set mxcd.dwControlID=(some number) to control Volume and Mute on any one of the controls.
 It all works just like I want.
 
 On a second computer that has two sound cards this doesn't work.  I can only get it to work when mxcd.dwControlID=1 and that only controls the Master channel.
 
 My question: Is there something I need to do to specify sound cards?
 There is quite a bit going on in the SetAudioVolume , may you could show a bit more uses and examples?
 
 Like I've noticed by adjusting the channels I can get it to pan over to one side, but not the other...Any more on panning?
 The volume seems logrithmic or something...what could be changed to make it a linear taper? so that 0.5 would be right in the middle 0.75 would be 3/4 of the way up...I don't really understand int vi=(v*0x4000)+(pow(v 4)*0xBFFF).
 
 Thanks,
 Jimmy Vig
 |