Jump to content

Recommended Posts

Posted (edited)

I Have cut this code out of my main script. It seams i have a small problem.

Many months ago, i replaced my logitch drivers with my own autoit functions (as i use autoit wherever i can now). The code below is ment to do 4 things. Enable the side buttons to control volume, pause/play music, next/prev track and to that effect it all works very well but i have noticed a few times "I think during Dayz (Arma 2) and League of Legends (LoL) the game seams to stop my script from working. Meaning i cant control my volume or music from mouse.

Does anyone know why this is happening ?

#NoTrayIcon
#include 'WinApi.au3'
Local $MouseClick, $MouseSideButton, $MouseHoldAdlib
_WinAPI_SetWindowsHookEx(14 , DllCallbackGetPtr(DllCallbackRegister('MouseHook', 'long', 'int;wparam;lparam')), _WinAPI_GetModuleHandle(0)) ;Mouse Hook

While 1
sleep(2500)
WEnd

Func MouseHook($nCode,$wParam,$lParam)
Switch $wParam
Case '0x20B', '0x20C' ;Side Buttons
$MouseClick+=1
If $MouseHoldAdlib Then
$MouseHoldAdlib=Adlib('VolUp', '')
$MouseClick=Adlib('VolDn', '')
ElseIf $MouseClick=1 Then
$MouseSideButton=DllStructGetData(DllStructCreate('struct;long X;long Y;endstruct;dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo',$lParam),3)
AdlibRegister('MouseHookDetection',225)
EndIf
Return 1
Case '0x20E' ;Wheel Buttons
If DllStructGetData(DllStructCreate('struct;long X;long Y;endstruct;dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo',$lParam),3)=7864320 Then Return ControlClick('Windows Media Player','WMPAppHost','[CLASS:WMPAppHost; INSTANCE:1]','Left',1,1000,1025)
If DllStructGetData(DllStructCreate('struct;long X;long Y;endstruct;dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo',$lParam),3)=4287102976 Then Return ControlClick('Windows Media Player','WMPAppHost','[CLASS:WMPAppHost; INSTANCE:1]','Left',1,900,1025)
EndSwitch
EndFunc

Func MouseHookDetection()
If $MouseClick=1 And $MouseSideButton=131072 Then $MouseHoldAdlib=Adlib('VolUp', '25')
If $MouseClick=1 And $MouseSideButton=65536 Then $MouseHoldAdlib=Adlib('VolDn', '25')
If $MouseClick=2 And $MouseSideButton=131072 Then $MouseClick=Not VolUp()
If $MouseClick=2 And $MouseSideButton=65536 Then $MouseClick=Not VolDn()
If $MouseClick>2 Then $MouseClick=-ControlClick('Windows Media Player','WMPAppHost','[CLASS:WMPAppHost; INSTANCE:1]','Left',1,950,1025)
$MouseSideButton=Adlib('MouseHookDetection', '')
EndFunc

Func Adlib($Function, $Time)
If $Time Then Return AdlibRegister($Function, $time)*0+1
If Not $Time Then Return AdlibUnRegister($Function)*0
EndFunc

Func VolUp()
Return Run('"C:\Program Files (x86)\Scripts\Source\Includes\Software\nircmd.exe" changesysvolume 1250')
EndFunc

Func VolDn()
Return Run('"C:\Program Files (x86)\Scripts\Source\Includes\Software\nircmd.exe" changesysvolume -1250')
EndFunc

**NirCmd.exe is a windows command ulity. http://www.nirsoft.net/utils/nircmd.html

I dont belive there is a fault in the code, as that works 99.9% of the time for all other windows. I belive the game is preventing my hook from working but wanted to get others views.

Edited by IanN1990
Posted (edited)

I didn't infact, such a thought didnt cross my mind. Though i reading what you said i found it weird that LoL would block autoit but it did give me the answer.

To play LoL on Windows 7, the game has to be run as "Admin". I run my script has normal, and i remember from the past autoit cant interaction with things that are "admin" unless autoit is admin.

So Adding #RequireAdmin Solves the problem.

Edited by IanN1990
  • Moderators
Posted

IanN1990,

such a thought didnt cross my mind

Well, please make sure it does before you post anything like this again. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...