Posted by wmorrison on Mon, 06 Dec 2010 01:35:12
I found this page:
I copied and pasted the code on that page into the OnClick tag for a button in my Addon. It's very basic, just shows a frame with a button on it.
When I enter WoW and click the button, the code that assigns mouselook to Z works. I can press Z and mouselook is activated. But the two calls to SetMouselookOverrideBinding don't change the behavior of my left and right mouse buttons. Any ideas what could be wrong?
Posted by jnwhiteh on Mon, 06 Dec 2010 11:43:23
It works properly for me. When I run that code, I can press and hold 'z', and use the left mouse button and right mouse button to move forward and backward accordingly. What isn't working for you?
Posted by wmorrison on Mon, 06 Dec 2010 21:12:10
What happens is:
Holding Z allows mouslook (cursor disappears and field of view changes when mouse is moved, as expected) Holding left mouse button works as default (mouselook but doesn't actually turn character) Holding right mouse button works as default (mouselook and turns character)
Is there a place here to upload test addons? I didn't see a way to attach files to a post.
Could it be a conflict with another addon? I can try disabling all other ones tonight.
This is my first experiment with wow addons, although I am a programmer by profession.
Posted by wmorrison on Tue, 07 Dec 2010 02:28:09
Just tried with a character for which all other addons were disabled. Still doesn't work. :(
Is there a place to share addons under development on here?
Posted by wmorrison on Wed, 08 Dec 2010 19:30:51
Is that code correct as-is, or am I supposed to substitute anything, e.g. BUTTON1 and BUTTON2? Are they literal?
The code is running because I can put print statements before and after and see them.
If it works for you, could I get a simple addon to test if it works for me? Or can I send you my addon to see if it works for you?
Posted by jnwhiteh on Thu, 09 Dec 2010 11:33:09
You don't need an addon to test this. Download WowLua from WowInterface (there' a link from this site under Utils) and copy/paste the following code EXACTLY into the in-game editor:
-- Uses the 'z' button to activate mouselook instead of the mouse buttons, -- and the mouse buttons to move forward and backward instead of mouselooking. -- Credits to slouken for this code. CreateFrame("Button", "MouselookButton") MouselookButton:RegisterForClicks("AnyUp", "AnyDown") MouselookButton:SetScript("OnClick", function (self, button, down) if ( down ) then MouselookStart() else MouselookStop() end end) SetOverrideBindingClick(MouselookButton, nil, "Z", "MouselookButton") SetMouselookOverrideBinding("BUTTON1", "MOVEFORWARD") SetMouselookOverrideBinding("BUTTON2", "MOVEBACKWARD")
Then click the 'Run' button, and exit WowLua.
Hold down the 'z' key, and click the left mouse button, you should move forward. Click the right-mouse button (while still holding down 'z'). You should move backwards.
That's how I tested this.
Posted by wmorrison on Thu, 09 Dec 2010 15:58:54
Thanks. WowLua looks like a very useful addon.
I tried what you said, and got the same result. The part that reassigns mouselook to another key works, but the part that overrides the mouse buttons does not.
No addons except WowLua were enabled when I tried this.
So something's funny with my system, maybe? Is it possible that BUTTON1 and BUTTON2 are not always the mouse buttons on all systems? So the WoW executable knows what they are, and uses the correct buttons (on a hardware level, maybe) but I would need to use different identifiers?
I tried the GetMouseButtonClicked() function, thinking it would tell me. It returned something like "LeftButton" (can't check that exactly right now) which I assumed was not the same string as I should use for BUTTON1, but I swapped it in anyway, but it didn't work either.
Posted by jnwhiteh on Thu, 09 Dec 2010 16:03:08
The binding key
BUTTON1is different from the mouse button clicked, which is reported properly as LeftButton/RightButton. They're different systems, so they have slightly different APIs. I really have no idea why this isn't working for you.
When you're holding down the 'Z' key, run the following script:
/dump GetBindingAction("BUTTON1", true)
Posted by wmorrison on Fri, 10 Dec 2010 01:25:58
Hmmm... Ya know, I really think it IS my system now.
The whole reason I was messing with this was that I tried wwwXorIO's "Mouse Combat" addon, and it didn't seem to work very well. That is, it can start and stop MouseLook with a key, but doesn't override the mouse buttons. After looking at the code, it does appear to be attempting to override the mouse buttons with SetMouselookOverrideBinding, but it has no effect, just like I experienced when I used the code here.
What happens with "Mouse Look" is:
I press the toggle key I configured, and MouseLook starts. (As expected.)
I press the left mouse button and my character runs as if both mouse buttons were being pressed. (It's supposed to be mapped to an attack by default.)
I release the left mouse button and press the right. No noticeable change (stays in MouseLook) until I release the button, which stops MouseLook.
However, the addon still has a variable set that says MouseLook is on, so I have to press the toggle key TWICE before the addon starts MouseLook again.
So I guess there should be no need for me to re-invent the wheel, if I could figure out why SetMouselookOverrideBinding isn't working on my system for BUTTON1 and BUTTON2.
Posted by wmorrison on Fri, 10 Dec 2010 03:03:27
Scratch that, Mouse Combat is broken for some other reason.
It's out of date, but I loaded it anyway. It seems to break when calling this:RegisterEvent, and never binds the mouse buttons. Is "this" deprecated with Cataclysm? I recall some things were, but can't find that info again now.
Anyway, if I comment out the calls to RegisterEvent, at least I can see that my left mouse button now attacks, so I'll have to examine the Mouse Combat code to figure out how it's working.
Posted by jnwhiteh on Fri, 10 Dec 2010 08:10:59
'this' has been deprecated. The way script handlers work now is that the first argument to any script handler is 'self', which is the frame that is generating the event. It's not as simple as replacing 'this' with 'self', but it might just work.