Pages: 1
Print
Author Topic: how to work with key press event and write to task bar?  (Read 1014 times)
biswajitsr
Member

Posts: 44


« on: June 28, 2010, 12:18:53 AM »

how to work with key press event and write to task bar?
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1552



WWW
« Reply #1 on: June 28, 2010, 11:54:00 AM »

Please provide a detailed description of what you are attempting to do. Please also provide as much information about your current solution so we have some context.
Logged
biswajitsr
Member

Posts: 44


« Reply #2 on: June 28, 2010, 11:09:37 PM »

actually we want to show the running character count. i.e. when user will type something on the editor the character count will be shown on the status bar. We are able to show the character count from the menu item click but is not able to show running character count, as didn't get the onkeypress or text change kind of events. So is it possible?
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1552



WWW
« Reply #3 on: June 29, 2010, 12:49:49 PM »

There is no OnKeyPress event so the only other solution would be to use the On_Update_UI event. This event fires very frequently (whenever the UI is updated), and perhaps frequently enough to run your script. See the Programmer's Guide for a more complete description.

To clarify this a bit more, as you don't have direct access to key presses (to capture any and all key presses) you may need to count the number of characters in the current element or whatever other context you need to tell the user about.

Perhaps something like this:
//XMetaL Script Language JScript:
if(Selection.IsInsertionPoint) {
   var charCount = Selection.ContainerNode.Xml.length;
   Application.SetStatusText(charCount);
}


However, that will include surrounding tags, child tags and other things, including entities, comments, PIs, etc, which might not be what you want, so manipulating that further to selectively remove these other things might be necessary.

You might wish to have a look at the following "word count" script for inspiration on how to start stripping out unwanted things to give an accurate count:
http://forums.xmetal.com/index.php/topic,28.msg37.html#msg37

Or you could use Range.Text instead after moving the Range to an appropriate location.

Whatever script you come up with would probably need to be put inside the On_Update_UI event if you need to constantly update what is displayed in the status bar.

An alternative, if you can restrict this character count reporting to specific elements only, would be to implement an XFT form or VB or other type of dialog for that element and have the user enter this text into a textbox that has the equivalent of an OnKeyPress or OnChange event and then do something similar to the above by getting the length of the equivalent of a "text.length" property for the control on the textbox control on the form.
« Last Edit: June 29, 2010, 03:27:07 PM by Derek Read » Logged
Pages: 1
Print
Jump to: