Customizing Keystrokes

I want to allow users to customize keystrokes in my application. (This is an application for internal use with about 30 users). What is the best way to do this?
It is easy to hard-code specific keystrokes in the application: for instance if up-arrow moves the cursor up one in a list (default behavior), I can hard-code Ctrl-up arrow to move the current line in the list up one, swapping it with the line above. Or I can hard-code the "+" on the number pad to do this (because "+" implies "up one") or the "-" line (because the "-" key is above the "+" key). I just can't decide which, and I don't expect all the users to agree.
It's also easy to use characters instead of keystrokes and have the user specify characters in a preferences dialog. For instance "Move current to top: Aa1" specifies that the A key (shifted or not), the non-shifted 1 key on the alpha keyboard, or the num-locked 1 key on the numeric pad will each perform the action. "Move current object up one: +" specifies that either way of typing a "+" will move the current object up one. But you can't distinguish between the two "+" keys this way and you can't specify Ctrl-+ or the up-arrow key.
What is the best way to allow the user to select arbitrary keystrokes? Do I have to write a parser and have him type in "Shift-UpArrow" as if he could remember all the names for things, or even worse, "VK_SHIFT + VK_UP" for one up-arrow, "VK_SHIFT + VK_KP_UP" for the other? Users won't accept that. I can listen for a keystroke, but what's the best way to display it for confirmation? Is there any such thing as a "Keystroke Chooser" analogous to JColorChooser?
I know I could spend a month crafting a dialog with a drop-down list of all keystrokes etc. Is there a simpler, quicker way?

I would do it the way it's done in computer games. You display a list of available actions along with the keystrokes that are currently bound to them. The user elects to change one of the bindings by, e.g., double-clicking on it. A textfield appears (or the program indicates in some other way that it's waiting for input). The user presses a key combination, and that keystroke is added to the bindings for the action (or it replaces an existing binding). If the keystroke is already bound to another action, you display a confirmation dialog before re-binding it.
That way, your users don't have to remember the names of the keys. But, to avoid confusion, you should use the same naming scheme as is used for shortcuts in menuitems.
Obviously, there are a lot of details to work out, but I think this is the best approach. One of these days, I may even try to implement it. :D

Similar Messages

  • Custom Keystroke Script

    hi. what i want do is if in text field text reached the end of one text field it will simply go into the next text field. aso i have found bellow code. my problem is other than adding next text field name, possible add any common name to auto select to next field( as per tab order). thanks..
    // Move to next field when this one is full
    if (event.fieldFull) {
        getField("NameOfNextFieldGoesHere").setFocus();

    Only if one carefully choices field names that can be calculaed form the field name.

  • Please help with a custom javascript

    Hello,
    I am a military instructor, and I am trying to create a grade report card with Acrobat X Pro.  So far I have made good progress with the help of the forum community (just searching through the pages and pages of posts), but I am stuck on this issue.
    Like I stated,  I am creating a report card (of sorts) where our other instructor staff can input student test grades into the fields as they [students] progress through training.  The form is showing the particular test with an input field for the grade.  Lastly, the student's overal GPA is displayed in percent format.
    My conundrum: I am trying to code a field that all a user [instructor] will have to input is a numerical value with or without a decmil, and the field will display it as a percentage. 
    If I use acrobats default percentage, the number entered into the field will be multiplied by 100 (i.e. I enter 90 and acrobat displays 9000% in the field).
    I would just like to be able to type in 90, and 90% be displayed; or type in 88.5, and 88.5% be displayed.
    With the scripts I have entered, no decmils can be displayed, and the overal score is multiplying the average by 100, thus if I entered the number 90 in the first exam, the average calculates to 9000%.
    I am assuming the custom format script and custom keystroke script made the average calculation script not work correctly.
    Thanks in advance.  Ryan
    I have entered the following javascripts:
    1.  Document Level Script
    // Document-level function
    function DigOnlyKS() {
        // Get all that is currently in the field
        var val = AFMergeChange(event);
        // Reject entry if anything but digits
        event.rc = AFExactMatch(/\d*/, val);
    2.  Custom Format Script
    // Custom Format script for text field
    if (event.value) event.value += "%";
    3.  Custom Keystroke Script
    // Custom Keystroke script
    DigOnlyKS();
    4.  Custom Calculation Script for an Overal Grade Average
    event.value = myAverageFunction(["pk1","pk2","pk3","pk4","pk5","pk6","pk7","pk8","pk9","pk10","pk11","p k12","pk13","pk14","pk15","pk16","pk17","pk18","pk19","pk20","pk21","pk22","pk23","pk24"," pk25"]);
    function myAverageFunction(aNames) {
        // n = number of fields that have a numerical value
        // sum = some of values for the named fields
        var n = 0;
        var sum = 0;
        var v;
        // loop through array of name strings
        for (i = 0; i < aNames.length; i++) {
          v = this.getField(aNames[i]).valueAsString;
          // check for not a null string and not a space  and not is Not a Number
          if (v != "" & v != " " & isNaN(v) == false) {
             n++; // increment count
             sum += Number(v); // add to sum
        return (n != 0) ? (sum / n): "";

    Try,
    I'm sorry for being so ignorant with javascript.
    I placed that code in the custom keystroke like you suggested, but it did not work.    Is there a specific way I need to input that code in the custom keystroke area?
    I then tried to put it in the document level code and replaced (/\d*/, val) with your code... that really screwed thing up.
    So now I am stuck where I was before.
    I will try and show you what I am trying to accomplish:
    Right now, this is what is happening
    Exam 1
    Exam 2
    Exam 3
    Final Average
    95.5%
    95.3%
    94.3%
    95.033333%
    What I would like to do is to limit each field to 2 decmil places.
    Each "exam field" has the following:
    The "final average" field has the following:
    and this is in the custom calculations area of the "final average" field:
    Finally, I have this in the Documet JavaScripts area:
    I have a feeling this is an easy fix, but I just cannot figure it out.
    Thanks,
    Ryan

  • Custom Date for Birthdate entry

    I got issued a project that requires me to take a pre-exsisting professional Scholarship form and make it into a PDF. I've been able to make the form fields with no problem but I'm running into a few issues with the Date format.  This form requires the Applicant to type out their Birthdate and Social Security #, however, the higher ups don't like the default method Acrobat uses.
    Problem #1: Because some of our Applicants are Elderly and/or are not very computer literate, I want there to be "some" flexibility to them typing out their birthdate.  IE, MDDYY, MMDDYY, MDDYYYY, MMDDYYYY will Validate through a script that turns it into the company standard format of MM/DD/YYYY.  I have a very basic bit of Custom Keystroke script that I found and edited slightly.  Its not pretty though.
    var a = event.value;
    if(a.length==5){var b = util.scand("mddyy",a);event.value = util.printd("mm/dd/yyyy",b)}
    if(a.length==6){var b = util.scand("mmddyy",a);event.value = util.printd("mm/dd/yyyy",b)}
    if(a.length==7){var b = util.scand("mddyyyy",a);event.value = util.printd("mm/dd/yyyy",b)}
    if(a.length==8){var b = util.scand("mmddyyyy",a);event.value = util.printd("mm/dd/yyyy",b)};
    This does what I want it to do, sort of, but deviating outside of this script results in undesired results. IE typing 02/13/71 will get 02/13/71 not 02/13/1971.  Then there's a potential problem of the century. Typing 021327 will get 02/13/2027 not 1927.
    Can anyone lead me in the right direction of where to close the flexibilty off at giving an Audio Alert when any other keystroke besides 0-9 and / is entered while maintaning the Validity of the above format of MM/DD/YYYY?
    (I realize this is pretty much nitpicking, but the higher ups say jump and I have to say How High and I'm not at the skill level yet to achieve the desired results.)
    Problem #2: In the same form, the Applicants SSN needs to be entered but the default format under Properties > Format > Special is requiring the full 9 digits. However, we have more than a few people who have "less" than 9 digits.  Given that the higher ups want to give some flexibilty to Elderly and non-computer literate on the SSN field as well, I've been asked to correct this problem.  Now, I've been steered in the direction of Leading Zeros script and AutoTab features, but to be honest, most of this is beyond my understanding in how to achive it. I understand the concept of leading 0's in the util.printd feature of the 999-99-9999 format, however, any attempt to do this stuff leads in undesired results.  Please help if you can.
    Thanks in Advance,
    Dean

    Thank you for replying Gkaiseril, not really sure what you're talking about with RegExp, hidden Fields and the like.  As I stated above, my skills with acrobat are limited and my knowledge of Java script is less than that.  Could you give examples or write out examples of what you're talking about?  I plan to learn more on Java, scripting and getting better at Acrobat, but for the mean time, I just need the scripting of how to get the Date field to do what I want it to do.
    As for the SSN, I'm aware of the 9 digit limit, this is why I'm wanting the script to fill in less-than-9-digit SSN's with leading Zeros.  We have had examples of the past of our clients and applicants with Exm 001-34-5678 not entering their 0's first and it confuses them as why their paperwork was'nt accepted or returned invalid.  Plus, our OCR system doesn't like the SSN field if its entered incorrectly.  This is why I was directed to look at leading 0's and something about a decimal point ...
    I haven't looked into the util.printd yet, in fact I know absolutely nothing about it except from what you told me.  No idea where to look for the things I want to accomplish.

  • Add (concatenate) a string to the end of a numerical field value (custom format script)?

    Hello All!
    1) I have a form field where a customer can input mileage (e.g. 48,000)
    I would like to be able to dynamically place the comma in the proper place as well as add " miles" to the end of the value the user input.
    For example:
    If the user types "123456" into the field, I would like for it to display as "123,456 miles"
    I assume this will require some custom format javascript... I'm familiar with the general syntax of JavaScript, but don't really know specific keywords/object names to use, I have a few custom calculation scripts in the form, and I've done some simple thing like concatenate two fields into one, etc.
    But this is a little different, because I'm only working with data from one field. I tried:
    event.value += " miles";
    However, this causes " miles" to get added everytime ANY field changes... so I end up getting "123,456 miles miles miles miles" as the user makes changes to other fields.
    2) Also, to further complicate things, is it possible to "remove" the custom formatting when the field gains focus? For example, if you use Acrobat's default number format ($1,394.00) on a field, when the user selects that field to edit the value, the formatting "disappears" so that the user would only see "1394".
    I would like to achieve the same with my custom field, so when the user selected the field that displays "123,456 miles" to change the value, they would only see/edit "123456"
    A bit wordy, I know, but thanks for any help!

    Here's a simple way. Begin by creating a new document-level JavaScript and include the following code:
    function my_format() {
        // Format number (no decimal point, comma thousands separator, etc.)
        AFNumber_Format(0, 0, 0, 0, "", false);
        // Add " miles" if there is an entry
        event.value = event.value ? event.value + " miles" : "";
    function my_keystroke() {
        // Restrict entry to characters consistent with a number
        AFNumber_Keystroke(0, 0, 0, 0, "", false);
    For the field in question, add the following as the custom Format script:
    my_format();
    and the following as the custom Keystroke script:
    my_keystroke();
    George

  • Creating a custom format for angles that adds a degree symbol

    I am creating a fillin form.  I would like to customize the format of a number field to add a degree symbol to the numbers added by the user.  So when the users types in 90 a small elevated circle representing degrees automatically appears after the digits.  Can I do this?

    OK, probably the easiest way is to take advantage of Acrobat's built-in formatting routines for a number and adapt it to use a degree symbol. In the sample linked to below I created a document-level JavaScript and added the following two functions:
    function degreeFormat() {
        AFNumber_Format(0, 1, 0, 0, "\u00b0", false);
    function degreeKeystroke() {
        AFNumber_Keystroke(0, 1, 0, 0, "\u00b0", false);
    Which get called from the field's custom Format and Keystroke events, respectively:
    // Custom Format script
    degreeFormat();
    // Custom Keystroke script
    degreeKeystroke();
    Here's where you can download a sample: https://acrobat.com/#d=t241U3Pj0w0FztiQw5jgSw
    This allows decimal entries, but rounds to the nearest whole number for display. If you don't want a user to enter a fractional part, the script is a bit more complicated, but can be done.

  • Can you retrieve custom workspaces, menu settings, etc?

    My department is getting new computers (Windows), which means we have to reinstall CS4 Design Premium. We have all set-up custom workspaces, custom keystrokes, menu preferences, etc. I'm pretty sure with Photoshop I can tell everyone how to save the brushes, actions, etc. files, but are there files that hold these other types of settings and where do they reside? We use Photoshop and InDesign almost exclusively.
    Maybe I'm grasping at straws here, but I'm hoping...
    Thanks!
    Lloyd

    See Replace Your Preferences
    What's stored where and how to back it up is covered.

  • Help with Regular Expression for field validation

    I'm fairly new to using regular expressions and using Acrobat. This is probably a simple question, but I've been unable to figure it out.
    I have a text field on a PDF that I would like to be 9 characters in length. The first 2 characters can only be alphanumeric, the last 7 characters can only be numeric.
    At first I was using the following, which allows all the characters to be alphanumeric:
    var re = /^[A-Za-z0-9 :\\_]$/;
    if (event.change.length >0) {
    if (event.willCommit == false) {
        if (!re.test(event.change)) {
            event.rc = false
    That works fine, but it's not quite what I needed. With some assistance I changed it (see below) to fit what I was looking for. However, this didn't work; it prevents anything from being entered in the field:
    var re = /^[A-Za-z0-9]{2}\d{7}$/;
    if (event.change.length >0) {
    if (event.willCommit == false) {
        if (!re.test(event.change)) {
            event.rc = false
    Any help would be greatly appreciated.
    Thanks...

    Here's a function you can call form the field's custom Format script. It should be placed in a document-level JavaScript:
    function custom_ks1() {
        // Define non-commited regular expression
        var re = /^[A-Za-z0-9]{0,2}([0-9]{0,7})?$/;
        // Get all of the characters the user has entered
        var value = AFMergeChange(event);
        // Allow field to be cleared
        if(!value) return;
        if (event.willCommit) {
            // Define commited regular expression
            var re = /^[A-Za-z0-9]{2}[0-9]{7}$/;
            if (!re.test(value)) {  // If final value doesn't match, alert user
                app.alert("Your error message goes here.");
                // event.rc = false
        } else {  // not commited
            // Only allow characters that match the regular expression
            event.rc = re.test(value);
    Call it like this:
    // Custom Keystroke script
    custom1_ks();

  • Minimize All Open Windows

    Hello:
    I am using Photoshop CS2 on Win XP machine and was wondering if there was a keystroke to minimizing all open windows or can that be set up in custom keystrokes.

    ALL open windows, or all open document windows within Photoshop?
    To minimize ALL open application windows, press and hold the left "Windows" key. While holding that key, press "M". The "Windows" key is the quad twisted square key, usually between the Ctrl and Alt keys. Some people actually think the key looks like the Windows logo.
    (has nothing to do with Photoshop)

  • How to format a text field for credit card numbers?

    OK, I found this conversation, http://forums.adobe.com/message/3598185, that gave some useful insight, and I adapted the code presented in it to make sure the user types in a 16-digit number, and it tells them to do it right if they don't.
    Here's my problem:
    With the code as given, I can either get a single string of 16 digits (i.e.: 1234567890123456), or, I have to make the user manually type in the spaces to get the usual CC format (1234 5678 9012 3456).
    What I'm hoping for is some code that will let me allow the user to simply type in 16 uniterrupted digits, but that will then display that entry in the expected format. (So, user types 1234567890123456, but the field once they tab or click out of it will show 1234 5678 9012 3456)
    Here's the code I have thus far (like I said, copied alomst verbatim from the link above):
    In the Format tab, under Custom Format Script:
    function checkFormat(s) {
        if (!s) return true;
        var aRE = [
            /^\d{16}$/
        return AFExactMatch(aRE, s);
    In the Format tab, under Custom Keystroke Script:
    (function () {
         if (event.willCommit) {
             var isValid = checkFormat(event.value);
             if (!isValid) {
                app.alert("Please enter a valid 16 digit credit card number with no spaces or dashes.", 1);
                event.rc = false;
    I'm sorry it's so simplistic. Though I've rooted around in other programming languages (HTML, C++), so I'm not a complete noob, I don't know anything about Java at all...
    Thanks in advance!

    Acrobat uses JavaScript and not the Java programing language.
    Many script samples are for different variations of JavaScript and Adobe has its own variation.
    Also if you make spaces or other white space characters part of the value, you need to remove them from the validation.
    A custom validation script could be:
        var cardValid = function(cardNo){   
        var sum = 0, iNum;
        for( var i in cardNo += '' ){
                        iNum = parseInt(cardNo[i]);
                        sum += i%2?iNum:iNum>4?iNum*2%10+1:iNum*2;
        return !(sum%10);
    // process non-blank values
    if(event.value != "") {
    // strip blanks, "-", or "."  from value
    var cCardNumber = event.value.replace(/[- .]/g,"");
    if(cardValid(cCardNumber) == false) {
    app.alert("Invalid Number.\Please re-enter.", 1, 0, "Invalid card Number");
    event.rc =  false;
    } // end not empty value

  • How can I change the key to delete a message from the delete key to command-delete like it is in the finder?

    These new forums confuse me... Sorry.
    I often think I am typing in another window but I'm actually typing while Mail.app is selected.  When I discover this, I often (without really thinking) start whacking the delete key.  When I whack the delete key, of course, a message is moved to the trash.  So, without really thinking about it, I delete three to six messages.  Go ahead -- call me stupid.  But...
    If delete is not used to delete files in the Finder, then why is it used to delete files in Mail?
    One group suggested making customer keyboard macros.  Sounded like a plausible solution.  I could make a customer keyboard macro so that delete did nothing (or something benign) and make command-delete delete the message.  Alas, using the Apple => System Preferences => Keyboard => Keyboard Shortcuts => Application Shortcuts gave me no Joy because it won't let me do either of those.  When I try to enter either delete or command-delete into the "Keyboard Shortcut" box, it just beeps at me.
    Does anyone here have a suggestion?
    Thank you,
    pedz
    p.s.   I can get the deleted messages back using Undo (repeatedly) but I think that is new with Lion.  So life isn't tragic but it still is an interface that I'd like to change if I could.

    You can define your own custom keystrokes in System Preferences -> Keyboard.  I'm not 100% sure that this blocks the old keystroke, though, and am posting from my iPad and can't check that at the moment.

  • How do I set a form field to accept whole numbers only?

    I am using Acrobat X.
    I have a number of fields in a form that are used in a variety of calculations. It is the nature of these fields that they need to contain whole numbers only, no decimals.
    On the "Format" tab, I have set the field format to "Number" and the number of decimal places to "0"
    On the "Validate" Tab I have set the "Field Value is in Range" "From 0", "To 999"
    This is to ensure that the field can only contain a maximum of a three digit number.
    But this still allows the user to enter decimal places. This messes up my calculations so I want to limit the user's input to whole numbers.
    How do I do that?
    Thanks!
    Steve

    I apologize for being dense but I really do not know how to apply your solution. Taking the path you suggested there is nothing under Tools>Document Processing relating to Java scripts.
    I presume that I have to save this part somewhere in Acrobat:
    // Document-level function
    function triDigKS() {
        // Get all that is currently in the field
        var val = AFMergeChange(event);
        // Reject entry if anythig but digits
        event.rc = AFExactMatch(/\d{0,3}/, val);
    And then use the call out:
    // Custom Keystroke script
    triDigKS();
    Somewhere else but I don't know where thos two places are. Do I use the callout in the validation tab, or somewhere else?
    Thanks
    Steve

  • Need to format a form field to add a "%" after the number

    I am working on a form that will both print for manual fill-in and also electronic fill-in using reader. My issue  is that I need to
    add a "%" symbol after the number input by the user. I can't use the percentage format type because that places a 0.0% in the field
    when no data is entered and I can't have that due to the need to be able to print a blank form for manual fill-in. Is there a simpl
    e way to append the % character after the user input only if data is in fact input and to leave the field empty otherwise?

    I assume you only want the user to input numbers and you've then set the format to number.
    In the textfield properties go to the format tab and set it to custom.
    Enter a custom keystroke script:
    if(!event.willCommit)
    var nChars = event.selEnd - event.selStart;
    var aFull = event.value.split("");
    aFull.splice(event.selStart, nChars, event.change);
    var strFull = aFull.join("");
    event.rc = !isNaN(strFull);
    This will allow user to input numbers only - strings are regarded as user type.
    Go to the validation tab and enter a custom validation script:
    f = event.value;
    if(f) {
        event.value = f + " %";
    If I understood your question correctly, that should do the trick.
    Torben.

  • PDF Forms: problem with keypad "decimal dot" when filling "number" fields

    Ok, here's my problem :
    I've created a form with fields. My client want to input in those fields amount of money. So I've created fields formatted with the "Number" category. 2 decimals, "1234,56" separator style, not currency symbol. So far, so good!
    When testing out the form, here's what happening :
    On the computer that I've created the form (iMac, Acrobat Pro and Reader, french canadian keyboard layout and system)
    Using the keypad, I can input numbers, with the "decimal point" from the keypad no problem.
    But when the client is trying to to the same on his PC (and the same is happening with my PC at home, Acrobat Pro 9.2, french canadian keyboard layout and system), I CAN'T use the "decimal point" keypad key to input numbers (like 43,25). It's just not working (error sound). I can however use the "dot" on the keyboard near the "M" key, but the client don't want to do that.
    Why is it working on the Mac, but not on the PC's!?
    So far, the only workaround that I've found is to set the "money" fields categories to "none" instead of "number.

    It is a little bit tricky, but you might have to add your own formatting handler. You would proceed as follows:
    1. Set the Format to "none".
    2. Add the following script to a Custom Keystroke event:
    if (event.change.length > 0 && event.willCommit == false) {event.change = event.change.replace(/\,/gim, ".") ;
    3. Add the following script to a Custom Format event:
    event.value = event.value.toString().replace(/\./gim, ",") ;
    And that should take care of the situation.
    Note that i have not tested the scripts, and there may be a chance for bugs.
    The advantage of this solution is that internally, you will have the correct format for a number, so that calculations will be correct.
    Hope this can help.
    Max Wyss.

  • Combo box not behaving like it should

    I have a form in which I have 4 combo boxes that have more or less the same choices, however there is one that is common to all 4 (E078).
    When "E078" is selected in any of the combo box, a new combo box will appear (and a white rectangle will be hidden so that the new combo box title can be seen). It works when I select that in one or more combo box, however to make it disappear I have to select some other choice in the same combo box twice!!! If I select anything only once, it will not make the new combo box hidden, but if re-select something (same or another choice) then the combo box will disappear!
    I am at lost, and would be very thankful if someone could make it work seamlessly. I mean it works, nut it is just inconvenient and I cannot tell the user to make select something else twice if they want the field to disappear.
    Here is my form:
    https://workspaces.acrobat.com/?d=WjF6aV8IUuBX2w8iZN3k0g

    When you use event.value in a combo box's Validate event it does not give you the export value, which is what you want. It is easier to use place the code in a custom Keystroke script where you can use the event.changeEx property to retrieve the export value of the selected item. See the documentation for more information: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.607.html

Maybe you are looking for