Confirmed users
478
edits
Line 186: | Line 186: | ||
If the field is a numeric field, it will fill "1337". | If the field is a numeric field, it will fill "1337". | ||
var timer; | |||
var timer; | |||
function startTyping(inputContext) { | function startTyping(inputContext) { | ||
clearTimeout(timer); | clearTimeout(timer); | ||
timer = setInterval(function () { | timer = setInterval(function typing() { | ||
if (inputContext.inputmode = 'numeric' || inputContext.type = 'number') { | if (inputContext.inputmode = 'numeric' || inputContext.type = 'number') { | ||
inputContext.commitText('1337'); | inputContext.commitText('1337'); | ||
Line 211: | Line 198: | ||
inputContext.sendKey(k.charCodeAt(0), k.charCodeAt(0)); | inputContext.sendKey(k.charCodeAt(0), k.charCodeAt(0)); | ||
}); | }); | ||
}); | }, 1000); | ||
} | } | ||
function stopTyping() { | function stopTyping() { | ||
clearTimeout(timer); | clearTimeout(timer); | ||
} | |||
var im = navigator.inputMethod; | |||
im.addEventListener('inputcontextchange', function contextchanged(evt) { | |||
if (evt.inputcontext) { | |||
// Got a new context, start working with it. | |||
startTyping(evt.inputcontext); | |||
} else { | |||
// The user have removed the focus, we are not allow to type into the text field anymore. | |||
stopTyping(); | |||
} | |||
}); | |||
if (im.inputcontext) { | |||
// The webpage here is loaded *after* the user has place the focus on the text field, | |||
// let's start typing now. | |||
startTyping(im.inputcontext); | |||
} | } | ||