flat assembler
Message board for the users of flat assembler.

Index > Heap > simulate keypress in firefox browser

Author
Thread Post new topic Reply to topic
sleepsleep



Joined: 05 Oct 2006
Posts: 8885
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
hi,
been doing some php, javascript, html5 stuffs,

any idea how to simulate keypress using firefox browser, under html5 doc type?

i tried the following but it doesnt work, (firefox ESR 17.0.5)

Code:
var t1 = document.getElementById("test1");
var evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent("keypress", true, true, null, false, false, false, false, 97, 97);
t1.dispatchEvent(evt);
    

it would send (a) character to that input,
Post 14 May 2013, 14:57
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6034
Location: Poland
MHajduk
Maybe you should set focus to your edit field /window before you create a key event?
Code:
var t1 = document.getElementById("test1");
t1.focus();
var evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent("keypress", true, true, null, false, false, false, false, 97, 97);
t1.dispatchEvent(evt);
    
Post 14 May 2013, 15:27
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8885
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
tried the t1.focus();
but kinda weird, i googled for the past 1 hours, it seems no solution on this keypress simulate,

since HTML5 add something like
db 'Access-Control-Allow-Origin: *',CR,LF
if you want to ajax cross-domain,

maybe there is new policy regarding simulate keypress

because there are hacking issue i simulate ctrl+p (paste) your clipboard into my database

ah,,,
Post 14 May 2013, 15:33
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8885
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
here the bare snippet
Code:
<!DOCTYPE html>
<html>
<script>
function f(){
var i=document.getElementById("i");
alert( "a".charCodeAt(0) );
i.focus();
 var evt = document.createEvent("KeyboardEvent");
    evt.initKeyEvent("keypress", true, true, null, false, false, false, false, 0, 97);
    i.dispatchEvent(evt);
}
</script>
<body onload="f();">
<input id="i"/>
</body>
</html>
    

doesnt work in firefox ESR 17.0.5 damn it.
Post 14 May 2013, 15:37
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6034
Location: Poland
MHajduk
sleepsleep wrote:
maybe there is new policy regarding simulate keypress
Quite possible.

Look at the code I've found a few moments ago. Maybe it could be helpful (I'm not sure though): http://stackoverflow.com/questions/10455626/keydown-simulation-in-chrome-fires-normally-but-not-the-correct-key/10520017#10520017
Post 14 May 2013, 15:38
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
sleepsleep wrote:
because there are hacking issue i simulate ctrl+p (paste) your clipboard into my database
Indeed. And more than just that of course.

One thing to remember is to make webpages that work without JS, and only if the user has enabled JS to do some sort of enhancement that normal HTML cannot do. It is also desirable to keep the level of JS driven "enhancements" to a minimum. The current trend many sites have towards using JS to drive everything (even simple links) is not necessary IMO.
Post 14 May 2013, 15:57
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8885
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
well, i dont think a web application could work without JS, there are great potential there in JS, eg, the ajax HTML5 that allow binary transfer, i use this to interact with my fasm server, like HTML -> JS -> FASM server > device through xmlhttprequest

which in another word, able to control call any win api or device api,

i found another method to simulate keypress, since i trap keypress and keydown in my js class, well, this might be a solution i will use temporarily. damn it... it is tainted
Post 14 May 2013, 16:04
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8885
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
my solution is like below, maybe useful for those who still seeking

Code:
var ec = ee.charCode;
var ek = ee.keyCode;

var evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent("keypress", true, true, window, false, false, false, false, 13, 13);
this.keydown( cpos.iqty, evt);
this.keydown( cpos.iprice, evt);
this.keydown( cpos.idisc, evt);

if( (ec == ek) && ( ek == 13 ) ) alert("auto enter");
    


glad it works!
Post 14 May 2013, 16:08
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.