Results 1 to 3 of 3
Nov 8, 2010, 02:41 #1
- Join Date
- Jul 2010
- 0 Post(s)
- 0 Thread(s)
Function Onkeypress for cursor key
Here is the code:
Nov 8, 2010, 03:06 #2
There isn't any, but you can use the Unity function called GetMouseButtonDown(0). 1 is for the right button and 2 is for the middle button. There's a corresponding GetMouseButtonUp(0), as well as GetMouseButton(0), which returns true every frame as long as the mouse button is down.
- Join Date
- Apr 2010
- Melbourne, AU
- 17 Post(s)
- 1 Thread(s)
Alternately, you can set up a button in the input manager. That way you can make a mouse button, joystick button, gamepad button, keyboard key, etc. all do the same thing, and the button can be configured by the user when running a stand-alone build. Then you use GetButtonDown("NameOfButton")--depending on what you called the button in the input manager--as well as GetButtonUp and GetButton.
Nov 8, 2010, 03:08 #3
- Join Date
- Aug 2007
- 50 Post(s)
- 2 Thread(s)
What is cursor key? I don't have a key called that on my keyboard?
I can't tell what your script wants to do. Who is document.getElementById(nextfield) ? some other element with the id of "b0"?
You are also returning false. Is this to catch people using ENTER to submit the form without putting in any input? Yeah, I think browsers should force users to navigate focus to the submit button first, but it's too late: people are used to hitting enter, except when focussed on a textarea.
If you are trying to make sure something's typed in, you could try something different (without regard to which key is used... because this is not the same per keyboard. You can maybe get away with US keyboards all having the same keycode, but beyond those... most of the command buttons can be different. For example the : key may be different between browsers).
Read more about keycode and charcode trouble: http://www.quirksmode.org/js/keys.html
First, you could say
onblur(this), if this.value == ""
this.focus or whatever.focus
Though this should sufficiently annoy users : ) But if, when they leave the input, if it's empty, move the focus back to the same input (you could also try a return false in there too to stop submission).
You could also try onchange or onkeyup, but this may hurt users who are backspacing a field empty so they can change their answer.
Or you could just check all your inputs when the user tries to submit.
//check the inputs
//if their values == ""
//return true (let the form submit)
This would be faster if you have a lot of inputs, but it doesn't tell the user right away that something needs to be filled in.