How to detect pressed key on BlackBerry using JQuery Mobile? - javascript

I am using JQuery Mobile to developing my own app for BlackBerry based on WebWorks(HTML5,CSS3,JS) tecknologies.
On my layout div i have 3 input elements.
I am wont to detect BlackBerry enter key pressed in first input to focus on next input.
How i can check if hardware enter key(and other keys like "T","R","D") pressed using JQuery Mobile??

There's nothing specific to jQuery Mobile for this. You just need to add an event listener on the input and listen to the appropriate keypress event. You can find a nice explanation for them here.
Here's some sample code to get you started (not tested, you might need to debug):
$('#firstInput').keypress(function(event) {
if ( event.which === 13 ) {
$('#secondInput').focus();
}
);
In the event.which, the key code gets checked (13 is for enter). Other keys have different key codes. Be careful, I remember a bug on Blackberry that it wouldn't trigger the keypress event for backspace.
Be more specific about your problem if you need more details.

Related

How to take input on a mobile site without a input field

The user needs to press the key X for the function to run and it works perfectly where there is a physical keyboard but how can I force a virtual keyboard on the mobile version? I can't think of a way to do this without adding an input field.
document.addEventListener("keyup", function(event) {
if (event.keyCode === 88) {
newx();
}
});
function newx()
{alert("Hello");
}
<h1>Key in X</h1>
The repl I'm using this for -> https://home.ajkallivayalil.repl.co/
After some searching on Google, I came up with this, but I suggest you make another user experience, as #95faf8e76605e973 said. (e.g. a button)
If you have some sort of input field and make it hidden, like using display: none or visibility: hidden, you can use JavaScript to activate it anytime, thus bringing up a keyboard.
To do this, you just have to use .focus() on your element.
A link to the SO page I found.

Adding Javascript in Vaadin 6 to disable Tab key press

I am adding Javascript in Vaadin 6 by making a new empty component that only has my JS. Basically I just want to disable Tab key press event on my fields. I searched internet but not found any solution with in vaadin. So I suggested use js to disable Tab key event. The JS that is disabling Tab key is:
$( document ).ready(function() {
$(".v-absolutelayout-WebFormTable input").keydown(function(event) {
if (event.keyCode == 9) //tab pressed
{
event.preventDefault(); // stops its action
}
});
});
I am adding the component having the JS on my desired component. On first attempt, it worked as expected. But this solution is not reliable. It donot now works now.
Can any one tell me any relaible way to disable tab key press on fields? I just want to disable tab key on only selected fields, not on all of the browser page.
Check out the addShortcutListener method. You can use it to detect that the tab key has been pressed.

jQuery Keyboard shortcut plugin unbind does not work in my demo but does not show any errors

I am trying to use this jQuery Keyboard shortcuts plugin https://github.com/jeresig/jquery.hotkeys in my JavaScript app.
I am having an issue where the bind method which enables the event listener to start listening for my key presses works however the unBind method does not seem to be working.
Here is an example: http://jsfiddle.net/80k2uf3w/13/
// Enable our keyboard shortcut for the "number 1 key"
function bindOneKey(){
alert("keyboard Event listener is now listening for key number 1 to be pressed!");
jQuery(document).bind('keydown', '1',function (evt){
alert("keyboard key number 1 was pressed");
return false;
});
}
// Disable our keyboard shortcut for the "number 1 key"
function unBindOneKey(){
jQuery(document).unbind('keydown', '1');
alert("keyboard Event listener for key number 1 has been killed!");
}
// Demo buttons to enable/disable our Keyboard shortcut Event listeners
$(document).ready(function(){
$('#bindOne').bind('click', bindOneKey);
$('#unBindOne').bind('click', unBindOneKey);
}
HTML Buttons for Demo
<input type="button" id="bindOne" value="Bind 1 keyboard key" />
<input type="button" id="unBindOne" value="unBind 1 keyboard key" />
On that demo page after pressing the bind 1 button, you can then press the number 1 key on your keyboard and get an alert from the callback function.
After that if you press the unbind 1 button and then press the 1 key again, it still works instead of un-binding it!
Does anyone know what the problem could be?
This is just the most basic demo to show the functionality and the problem. My real app will basically enable the keyboard shortcuts when a Modal is opened and then disable/unbind them when the Modal is closed. That is why i need to get this working.
My other option is to find a new Keyboard shortcut library, there are about 50 of them it seems but I liked this one because it seems to be pretty lightweight and also built by a very well know JavaScript developer. So I am posting here to see if we can get this one working 100% first.
One thing to note is that on the GItHub page for the library it seems the test files are using a jQuery v1.4.x older version, perhaps that could be part of the issue but I am not sure as majority of the library works and also I get no console errors!
Thanks for any help
I found a similar question with someone else trying to do the same thing enable and disable the keyboard shortcuts as a Modal opens and closes using this library in this question jQuery Hotkeys - unbinding?
It seems there isn't any perfect solution so I will probably look at other libraries or maybe just manually code the key shortcuts I need with jQuery without a library. It might give me more control.

How can we capture a mobile device "Next" button key press in Javascript

Most keys on a mobile smartphone keyboard produce a keycode with the following code, however the "Next" and "Prev." buttons do not:
$('#txtRegMobileNumber2').keydown(function (e) {
alert('Key pressed: ' + e.keyCode);
});
How can I capture the "Next" button press (equivalent to the arrows in iOS) in Javascript?
This other question may be a duplicate, but seeing as how the code does not work for me I still need help. I've tried using e.which and keyup() to no avail.
If you are concerned in capturing when the user moved away from your text field, maybe consider the blur() JavaScript event?
https://developer.mozilla.org/en-US/docs/Web/Events/blur
Perhaps a bit late answer but this issue can be solved with adding inputmode property to your input and setting it's value to 'search' thanks to that the "Go"/"Next" button on the keyboard is replaced by "Enter" that behaves the same way as normal enter button on a traditional keyboard.
<input id="txtRegMobileNumber2" inputmode="search"
Docs:
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode
Use remote debugging with console output and press those keys to get the code.

auto repeat the up/down arrow key?

in firefox when im inside a input textbox and press down the up/down arrow key it doesn't autorepeat. how can i make that happen and control how many keypress it will fire up per sec?
UPDATE: i use:
$('#search_view #search').live('keydown', function(event) {
if(event.keyCode == 40) {
// code
}
});
but it just execute the code one time..i would like it to repeat when holding down the down-arrow.
Use .keydown() instead ..
quote from jQuery .keypress()
In addition, modifier keys (such as
Shift) cause keydown events but not
keypress events.
Arrows fall do not fall in the same category as Shift, but are treated in a special way ... the keydown will do the trick ..
Update
After your comment here is a sample that works in
FF 3.5.x and 3.0.11
IE 6, 7
Google Chrome 4.0.x
Safari 4.0.4
It only does not work on Opera (Edit: works on Opera 12.16) but it does not work with any key .. not just the arrows..
About the rate, you can not alter it from your code.. it is a system option (from BIOS and from keyboard settings in control panel -windows- )

Categories