General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion how to work with key press event and write to task bar?

  • biswajitsr

    how to work with key press event and write to task bar?

    Participants 2
    Replies 3
    Last Activity 12 years, 5 months ago

    how to work with key press event and write to task bar?

    Reply

    Derek Read

    Reply to: how to work with key press event and write to task bar?

    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.

    Reply

    biswajitsr

    Reply to: how to work with key press event and write to task bar?

    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?

    Reply

    Derek Read

    Reply to: how to work with key press event and write to task bar?

    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.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support