Detect a keypress in general (i.e. with onkeypress or $(selector).keypress()), and execute a function, which identifies the key pressed, and then executes another function if the key is the intended one.
Well, JavaScript has a mechanism where you could check all the key strokes and check event.keyCode and match it with whatever key/keys you want to do certain things.http://www.quirksmode.org/js/keys.htmlThat link has a little more information.This is the method I typically go with. If you're using JQuery, I think it has it's own methods for determining which key was pressed. The JQuery API documentation on their site will be your best friend for that.
The idea is right, but keyCode is not the actual value on the key. Each key has a code. Try alerting the keyCode in your check function. You'll be able to collect the keyCode values for whatever keys you want.[b[Edit:[/b] I also prefer onkeyup versus onkeypress. I don't know how much of a difference it makes, but it feels better to me.
So I can see the frame, rectangle, and circle. The code is supposed to move the ball with WASD. But no movement.
Well, I don't know much about SVG, but my first instinct would be to put alerts in your move function and make sure those are launching when they are supposed to.Edit: Also, if balls is a global variable, you don't really need to pass it as an argument to your move functions. I don't think that it's causing a problem, but it's unnecessary =PAnother point: you load the SVG image into your JavaScript and edit it, but there's nothing that I can see that actually commits those changes or updates the iframe. The changes look like they are only done to your JavaScript DOM. Maybe you should update your iframe with your DOM after each change.Again, I don't know much about SVG, but that would be another guess.
No problem =) Good luck.
Well, it doesn't look like you're saving back to the file. When you change the DOM, it doesn't (as far as I know) automatically save it to the file. You'll probably have to save it back via AJAX, or set the contents of the iframe manually.
Once again, did you commit the changes back to the file? If not, the file probably has the same contents. Your iframe loads from file, not the DOM.
How is the svg drawn?
However, it would be better to use the key codes in conditional statements.
you can definitely use numbers as cases for a switch statement.