Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Programmatically typing into a textbox (KeyboardEvent)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael Hofer  
View profile  
 More options Feb 14 2012, 12:05 pm
Newsgroups: mozilla.dev.tech.xul
From: Michael Hofer <dev-tech-...@erstes.ml1.net>
Date: Tue, 14 Feb 2012 18:05:55 +0100
Local: Tues, Feb 14 2012 12:05 pm
Subject: Programmatically typing into a textbox (KeyboardEvent)
Hello,

I want to programmatically type into a xul textbox (xulrunner 2.0).
While the following code does trigger the "not canceled"-alert, it
doesn't change the contents of the textbox:

XUL:
-------------------------------------

   <textbox id="testbox"/>

JS (triggered on button command);
-------------------------------------

   var test_el = document.getElementById("testbox");
   var evt = document.createEvent("KeyboardEvent");
   evt.initKeyEvent("keypress", true, true, null, false, false, false,
false, 65, 0); //65 is character 'a'

   var canceled = !test_el.dispatchEvent(evt);
   if(canceled) {
     // A handler called preventDefault
     alert("canceled");
   } else {
     // None of the handlers called preventDefault
     alert("not canceled");
   }

A similar example with MouseEvents (click) triggering a checkbox works
fine for me, but I can't get the KeyboardEvent working (entering text in
the textbox). Any help is greatly appreciated.

regards,
Michael


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neil  
View profile  
 More options Feb 14 2012, 12:37 pm
Newsgroups: mozilla.dev.tech.xul
From: Neil <n...@parkwaycc.co.uk>
Date: Tue, 14 Feb 2012 17:37:12 +0000
Local: Tues, Feb 14 2012 12:37 pm
Subject: Re: Programmatically typing into a textbox (KeyboardEvent)

Michael Hofer wrote:
> A similar example with MouseEvents (click) triggering a checkbox works
> fine for me, but I can't get the KeyboardEvent working (entering text
> in the textbox).

Have you set focus to the textbox?

--
Warning: May contain traces of nuts.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Hofer  
View profile  
 More options Feb 14 2012, 2:28 pm
Newsgroups: mozilla.dev.tech.xul
From: Michael Hofer <dev-tech-...@erstes.ml1.net>
Date: Tue, 14 Feb 2012 20:28:41 +0100
Local: Tues, Feb 14 2012 2:28 pm
Subject: Re: Programmatically typing into a textbox (KeyboardEvent)
Am 14.02.12 18:37, schrieb Neil:

> Michael Hofer wrote:

>> A similar example with MouseEvents (click) triggering a checkbox works
>> fine for me, but I can't get the KeyboardEvent working (entering text
>> in the textbox).

> Have you set focus to the textbox?

No, I didn't. But I tried it now (focus before dispatchEvent) and it
makes no difference (the element receives the focus, but still the
keypress shows no effect).

Also, on the working example with the MouseEvent, i don't need to focus
the checkbox (the event is dispatched directly to the element).

thanks,
Michael


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Hofer  
View profile  
 More options Feb 15 2012, 5:54 am
Newsgroups: mozilla.dev.tech.xul
From: Michael Hofer <dev-tech-...@erstes.ml1.net>
Date: Wed, 15 Feb 2012 11:54:51 +0100
Local: Wed, Feb 15 2012 5:54 am
Subject: Re: Programmatically typing into a textbox (KeyboardEvent)
Am 14.02.12 18:05, schrieb Michael Hofer:

> I want to programmatically type into a xul textbox (xulrunner 2.0).
> While the following code does trigger the "not canceled"-alert, it
> doesn't change the contents of the textbox.

First of all: It's not a xulrunner 2.0 thing (bug). I get the same
behaviour in Firefox 10.0.1 (via Real-Time XUL Editor from "Developer
Assistent" addon).

But I finally found the solution:

First, there's a problem with my use of initKeyEvent. For sending the
letter "A", you need to put the character code in the last parameter,
not the second last. So the correct call would be:

evt.initKeyEvent("keypress", true, true, null, false, false, false,
false, 0, 65);

If you wanted to send a non printable character (like backspace)
instead, you would do it the other way around:

evt.initKeyEvent("keypress", true, true, null, false, false, false,
false, 8, 0);

While this worked now for an html input field, it still wasn't with a
xul textbox. But since the XUL textbox contains an html input and makes
it available through the 'inputField' property, I'm dispatching the
event directly on the inputField now. That finally does the trick.

See http://pastebin.com/Lf7kj3VR for a working full code example.

regards,
Michael


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neil  
View profile  
 More options Feb 15 2012, 8:29 am
Newsgroups: mozilla.dev.tech.xul
From: Neil <n...@parkwaycc.co.uk>
Date: Wed, 15 Feb 2012 13:29:25 +0000
Local: Wed, Feb 15 2012 8:29 am
Subject: Re: Programmatically typing into a textbox (KeyboardEvent)

Michael Hofer wrote:
> Also, on the working example with the MouseEvent, i don't need to
> focus the checkbox (the event is dispatched directly to the element).

No, but the whole point of focus is to indicate where keyboard events
should be dispatched to. Anyway, as per your other post, I see you
managed to work out that character events need a character code to work
properly, and that XUL textboxes are actually an XBL wrapper around HTML
input fields.

--
Warning: May contain traces of nuts.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mrbunnylamakins  
View profile  
 More options Mar 19 2012, 5:15 pm
Newsgroups: mozilla.dev.tech.xul
From: mrbunnylamakins <squiresm...@gmail.com>
Date: Mon, 19 Mar 2012 14:15:33 -0700 (PDT)
Local: Mon, Mar 19 2012 5:15 pm
Subject: Re: Programmatically typing into a textbox (KeyboardEvent)
I am not by any means trying to go off topic, but since I seen in your code textbox is there any way of get a string or any other info into a textbox by chance? I was looking to get a vbox that pops up with textbox display some info. Too many people say forget that and do it in java which I hate.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »