1 2 Previous Next 15 Replies Latest reply on Jan 24, 2012 12:13 PM by philmodjunk

    Trying to Create "hot key" with trigger

    hsutton47

      Title

      Trying to Create "hot key" with trigger

      Post

      Hello, I am probably at an intermediate level with FM 10 Adv Pro, and I'm stuck on something that I cannot understand. I have a basic "main menu" layout with just a few buttons on it (no fields), and the first button is to simply go to a specific Browser layout and display specific records.  I have a script assigned to that button that filters out certain records and takes me to a browser layout with those records sorted and displayed.

      What I'm trying to do is create an alternative where I can just use the keyboard to navigate.  For example, in addition to just clicking on the button to Browse those records, I would like to just be able to tap the "b" character on the keyboard to Browse.  And once on that browse layout, tape the "m" button to return to the Main Menu.

      I've been playing around with Layout Setup, Script Triggers, OnLayoutKeystroke to run the script that pulls up the filtered browser.  But two things are happening:

      1: I find that the script runs regardless of what key I tap, not just the "b" key.

      2: When the browser layout comes up, I get an annoying dialog box with an OK button that states: Before typing, press Tab or click in a field, or choose the New Record menu command.

      So how do I restrict the trigger to only run the script when the "b" key is tapped (and same to return to the Main Menu by tapping the "m" key), and how do I keep that dialog box and the sound event from occuring?

      Thanks, Hershel

        • 1. Re: Trying to Create "hot key" with trigger
          raybaudi

          Script for the "b" key ( with OnLayoutKeystroke )

          If [ Code ( Get ( TriggerKeystroke ) ) = 98 ]
          Go to Layout [ "YourLayout" ]
          Exit Script [ result: 0 ] // do not type the string "result", but only 0
          End If 

          Note that the ExitScript [ result: 0 ] doesn't let that the "b" key is really pressed into the new layout, giving the dialog of your #2 point.

          • 2. Re: Trying to Create "hot key" with trigger
            hsutton47

            Wow, worked perfectly.  Thank you so much.  I looked up the ascii code for the "m" (109) and on the Browse layout set up a similar trigger for tapping the "m" key to return me to the Main Menu layout and it worked fine.

            On the Main Menu I have other buttons that take me to different layouts etc, and if I wanted to assign keyboard characters to those buttons, how can that be done if I can only assign one script trigger at the Layout Setup level for the OnLayoutKeystroke trigger?

            Would I have to build multiple conditions in the one script for various keystrokes?

            I'm not going to go crazy with this, but it's nice to know and helps me understand a lot.  I saw some examples where people were providing the answers that included the "Exit Script [result 0]" and of course I was doing the literal thing and it was not accepting my input so thank you for making that clear.

            • 3. Re: Trying to Create "hot key" with trigger
              hsutton47

              I think I'm off to a start, I just did three different conditions within the same script and now when I tap the "b" key I get the browser, the "a" key is the same as clicking on the Add New Record Button using my preferred layout, and from either of those layouts the "m" key returns me to the Main Menu.

               

               

              • 4. Re: Trying to Create "hot key" with trigger
                hsutton47

                ...however.. just realized a major problem.  when I am on a layout where there are fields, and I enter a field and attempt to select an item off the drop down list, if the first letter happens to be one of the keystroke-defined characters, the trigger fires up isntead of permitting me to edit the field.  Example, if I select 'a" in a field called Category, and the first item on the list begins with an 'a", when I tap the "a" key to select, the trigger fires up which is to add a new record, and I am taken out of that record and into a new blank record.

                So how can I prevent the trigger from firing up when I am in a field making an entry?

                • 5. Re: Trying to Create "hot key" with trigger
                  raybaudi

                  "So how can I prevent the trigger from firing up when I am in a field making an entry?"

                  Really simple.

                  When you are in a field, there is an active field name...

                  • 6. Re: Trying to Create "hot key" with trigger
                    hsutton47

                    ok i'm lost. i've been trying to figure out how to incorporate the "active field name" you reference in the script so it will permit editing as i go from field to field vs. firing up using the trigger script.  

                    • 7. Re: Trying to Create "hot key" with trigger
                      Sorbsbuster

                      Try Get ( ActiveFieldName ).  It returns blank if no field has focus.

                      • 8. Re: Trying to Create "hot key" with trigger
                        hsutton47

                        sorry guys but i'm learning as i go, and i cannot figure out where this (Get (ActiveFieldName) would go or be incorporated into a script so that as a field takes focus, the trigger goes dormant, and when you click away from a field so that no field is selected, the trigger becomes active again.

                        this is all unchartered territory for me.  i've been trying since last evening to figure it out on my own, but i'm lost.  from the snapshot of the script i provided earlier, can you share with me how that would be modified to fix this issue?

                        • 9. Re: Trying to Create "hot key" with trigger
                          philmodjunk

                          If [ IsEmpty ( Get ( ActiveFieldName ) ) ]

                              Put rest of your script here

                          End If

                          and now your script will only do something if the focus is not in a field.

                          • 10. Re: Trying to Create "hot key" with trigger
                            hsutton47

                            Hello Phil, you've helped me before but it's been awhile.  This worked for me, thanks!  So far it's functioning without any errors.

                            I was not sure if I should wrap the entire script with a If, End If around the existing If, End If but I tried that first and it worked. By the way, is there any way to cut and past the script you have displayed into a text file like Notepad or even direclty in here?  I am not able to figure out how to do that, so I am using the windows 7 Snipping Tool to just capture the screen and past it as a graphics upload here.

                            Thanks again for all your help.  Also thanks very much to raybaudi and sorbsbuster for getting me off to a great start.

                            Hershel

                            • 11. Re: Trying to Create "hot key" with trigger
                              philmodjunk

                              To paste a script as text to the forum:

                              1. You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here.
                              2. If You have FileMaker advanced, you can generate a database design report and copy the script as text from there.
                              3. If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format. (Use the HTML option on the database tab panel and paste the text into the forum's HTML editor.)
                              • 12. Re: Trying to Create "hot key" with trigger
                                hsutton47

                                I was able to find and generate the database design report.  I am amazed at how much FM 10 Adv Pro does!  I began studying and playing with it over the past couple years but due to family health issues with my parents, I am just now beginning to use it and learn more about it.

                                Yes, I was able to pull up the scripts and cut and paste one into Notepad or Word.  As far as printing to a PDF file, I am not having any luck figuring out how to do that.  I did download the Known Bugs List Database and looked around in there but could not find the Script Pretty box.

                                I am out of time today, but will play with it some more tomorrow.  But my main question right now is how do I print to a PDF file?  I cannot find that in the on line Help.  I know how to create PDF files from reports and layouts, but not scripts.

                                • 13. Re: Trying to Create "hot key" with trigger
                                  philmodjunk

                                  I you have FileMaker advanced, I wouldn't bother with PDF's of the scripts. You can just copy and paste scripts as text from the Database Design Report.

                                  In the known bugs list database, click the Bug Reports button, to bring up the bug reports layout, then click the "script pretty tab" in the tab control. It's just a useful little custom function "extra" that I threw in with the database file. There's a check box field that controls whether the formatting is simple return and space characters or HTML tags--an option I came up with so I can paste scripts to the forum.

                                  I use it one of two ways: 1) posting scripts to the forum and 2) Taking complex scripts out of the databse design report and pasting them into Word so that I can more easily see the If and loop block structure via the resulting indenting script pretty produces.

                                  • 14. Re: Trying to Create "hot key" with trigger
                                    hsutton47

                                    Wanted to show you the results of your efforts to help me.  Below is my working script which works error-free now and am able to document it and also provide a cut & paste editable version here using your scripts.  When I pasted directly from the ScriptPretty window to here it came up all left-jusitifed, did not look nice like it does in the ScriptPretty window.  But I saw an option here to paste from Word and you mentioned using Word as well, so I cut and pasted from ScriptPretty to Word, then used the button here (paste from Word).  I am going out of town for a while and will not be able to work further on this for a while, but in the past couple days i've made good headway thanks to your information, so thanks again.

                                    If [ IsEmpty ( Get (ActiveFieldName) ) ]

                                            #ascii 98=b (condensed HS default browse)

                                        If [ Code ( Get ( TriggerKeystroke )) = 98 ]

                                            Perform Script [ “HS Condensed Default List” ]

                                            Exit Script [ Result: 0 ]

                                            #ascii 97=a (add new PNR)

                                        Else If [ Code ( Get ( TriggerKeystroke )) = 97 ]

                                            Perform Script [ “New Record (PNR)” ]

                                            Exit Script [ Result: 0 ]

                                            #ascii 109=m (Main Menu)

                                        Else If [ Code ( Get ( TriggerKeystroke )) = 109 ]

                                            Perform Script [ “MainMenu” ]

                                            Exit Script [ Result: 0 ]

                                            #ascii 120=x (Exit Filemaker)

                                        Else If [ Code ( Get ( TriggerKeystroke )) = 120 ]

                                            Exit Application

                                            Exit Script [ Result: 0 ]

                                            #ascii 118=v (Titles to VIEW)

                                        Else If [ Code ( Get ( TriggerKeystroke )) = 118 ]

                                            Perform Script [ “View Titles” ]

                                            Exit Script [ Result: 0 ]

                                        End If

                                    End If

                                     

                                    1 2 Previous Next