General XMetaL Discussion
biswajitsr June 28, 2010 at 6:18 am
how to work with key press event and write to task bar?June 28, 2010 at 6:18 amParticipants 2Replies 3Last Activity 12 years ago
how to work with key press event and write to task bar?Derek Read June 28, 2010 at 5:54 pm
Reply to: how to work with key press event and write to task bar?June 28, 2010 at 5:54 pm
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.biswajitsr June 29, 2010 at 5:09 am
Reply to: how to work with key press event and write to task bar?June 29, 2010 at 5:09 am
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?Derek Read June 29, 2010 at 6:49 pm
Reply to: how to work with key press event and write to task bar?June 29, 2010 at 6: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:
var charCount = Selection.ContainerNode.Xml.length;
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:
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.
- You must be logged in to reply to this topic.