ID:1662361
 
(See the best response by Pirion.)
Halp my scrol, javascrip?




Problem description:

I made a feature request for capslock and mousewheel scrolling detection a while ago - but I kind of really need it now. I think it was Nadrew that said it is possible with javascript (a few times) but never answered my pleas on how to do it - since I couldn't get it to work at all.

This was months ago and I ran into another problem where scrolling would be a really good solution. So I figured I should make another attempt at it once more.

I'm writing this thread in case someone already knows how to do this or has advice. If I can get it working I might submit it to snippets or make a library so it's easier to find in the future for others.

Best response
Caps lock is apparently not possible. The most common work around appears to be here: http://24ways.org/2007/capturing-caps-lock/

For mouse wheel scrolling - take a look at http://www.sitepoint.com/html5-javascript-mouse-wheel/

Found in just a few minutes of search on the web. :)
That looks like the stuff I've found and I can't get it to work either. Thanks anyway.

So guess I have to wait for the html5 client?
Or we can start with the code you've got not working, and go from there.
mob/Login()
src<<output({"<script src="http://code.jquery.com/jquery-1.7.0.min.js" ><script language="Javascript">

$(window).attachEvent("onmousewheel", MouseWheelHandler);

function MouseWheelHandler(e) {

// cross-browser wheel delta
var e = window.event || e; // old IE support
var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
document.location.href = 'byond://?src=\ref
[src];action=wheelup';
return false;
}


</script>"}
,"javascript")
..()

client
Topic(t)
..()

var/nlist[] = params2list(t)

if(!nlist["action"]) return

if(nlist["action"] == "wheelup") world << "up"

if(nlist["action"] == "wheeldown") world << "down"

if(nlist["action"] == "mousetrack") world << "MOUSE TRACK"


I should note, I'm not that familiar with js - much less combining it with DM. I don't think it will work since most likely the browser has to be focused.
I created a smaller test script, using document and removing jquery.

{"<script language="Javascript">

if (document.attachEvent)
{
document.attachEvent("onmousewheel", function(e){alert('Mouse wheel has been detected!')})
}
</script>"}


This worked outside of BYOND, but not when placed inside - which is what you're seeing. attachEvent works with onclick, just not onmousewheel - so looking into it some more.

I wouldn't be shocked if it was a focus thing, but it is strange it won't work with focus either.
Hopefully the html5-client will solve things like this. I'll just work around it for now.