shortcut for function keys (F8;F9)[SOLVED]

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

shortcut for function keys (F8;F9)[SOLVED]

Post by atout66 » Tue Apr 22, 2014 2:20 pm

Hi to all,

Is there a way to make a shortcut for a button without the prior Ctrl or Alt or Shift keys ?
I can have Ctrl+F9, Shift+F9, etc., but I didn't find yet how to have only F9, or F8 keys.

Any idea ?

Kind regards, Jean-Paul.
Last edited by atout66 on Tue Apr 22, 2014 7:56 pm, edited 3 times in total.
Discovering LiveCode Community 6.5.2.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: shortcut for function keys (F8;F9)

Post by dunbarx » Tue Apr 22, 2014 3:42 pm

Hi.

Check out "rawKeyDown" in the dictionary.

This is a message, and you can use 65474 and 65475 as tools to do whatever you need to.

Craig

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: shortcut for function keys (F8;F9)

Post by Klaus » Tue Apr 22, 2014 3:45 pm

And also check the entry for the "functionkey" message :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: shortcut for function keys (F8;F9)

Post by dunbarx » Tue Apr 22, 2014 3:48 pm

Hmmm.

Did I misunderstand your question? Does this do what you want? In the card script:

Code: Select all

on functionKey var
   if var = 5 then answer random(999)
end functionKey
in a button script:

Code: Select all

on mouseUp
   send "functionKey" && "5" to this card
end mouseUp
Sort of the same idea. Do you see why?

Craig

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: shortcut for function keys (F8;F9)

Post by Klaus » Tue Apr 22, 2014 4:09 pm

Sounds more like this (in the card script):

Code: Select all

on functionkey tKEy
  if tKey = 3 then
    send "mouseup" to btn "that namely button that shall accept a function key as shortcut, YO!"
  end if
end functionkey
:D

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: shortcut for function keys (F8;F9)

Post by atout66 » Tue Apr 22, 2014 4:24 pm

Yes Craig, I see why, and the "functionkey" is exactly what I was looking for.
So I've put this code in the stack and it works fine :wink:

Code: Select all

on functionKey theKey
  if theKey is 9 then send mouseUp to button "BttF9"
  else pass functionKey
end functionKey
I suppose that if the handler is in the stack I can remove the "pass functionKey", right ?
Thanks to all of you :wink:

Kind regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: shortcut for function keys (F8;F9)[SOLVED]

Post by atout66 » Tue Apr 22, 2014 4:37 pm

It's strange because the script works with the <if> statement but not with the <switch> one ?

Code: Select all

on functionKey theKey
     switch theKey
           case theKey is 11
               send mouseUp to button "BttF11"
               break
          case theKey is 12
               send mouseUp to button "BttF12"
               break
          default
               pass functionKey
     end switch     
end functionKey
This code produce nothing :shock:
Why not :?:
Discovering LiveCode Community 6.5.2.

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: shortcut for function keys (F8;F9)

Post by atout66 » Tue Apr 22, 2014 6:46 pm

After some tries here is what I did finally in the code of the stack:

Code: Select all

on functionKey theKey
     if theKey is 12 then 
          send mouseUp to button "BttF12"
     else if theKey is 11 then 
          send mouseUp to button "BttF11"
     --else pass functionKey
end if
It works but the <pass> command makes an error while compiling, so that's why I leave as a comment...

Thanks and kind regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: shortcut for function keys (F8;F9)

Post by Klaus » Tue Apr 22, 2014 6:53 pm

Try this:

Code: Select all

on functionKey theKey
     switch theKey
           case 11
               send "mouseUp" to button "BttF11"
               break
          case 12
               send "mouseUp" to button "BttF12"
               break
          default
               pass functionKey
               break
     end switch     
end functionKey
8)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: shortcut for function keys (F8;F9)

Post by dunbarx » Tue Apr 22, 2014 7:30 pm

Hi.

What Klaus said.

Your construction is not syntactically correct, though it seems to read logically. When you set up a "switch", you have to think of each "case" as the VALUE you want to test, not a CONDITIONAL. Do you see that? It actually makes for a simpler control structure.

Read Klaus' example, and this should fall into place right away. Now you can try thinking about the following:

case thekey is 11

This will not throw an error, though, as you discovered, it did not work. Why? What does the phrase "thekey is 11" resolve to, that the case line had to deal with? 10 points if you write back with the answer today.

Craig
Last edited by dunbarx on Tue Apr 22, 2014 11:07 pm, edited 1 time in total.

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: shortcut for function keys (F8;F9)

Post by atout66 » Tue Apr 22, 2014 7:56 pm

Arrrghh ! I got it now :!:

Thanks to you, I didn't understand that the <case> statement expected a pure value :idea:
I was used to code otherwise, that's why :wink:

Kind regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: shortcut for function keys (F8;F9)[SOLVED]

Post by Klaus » Tue Apr 22, 2014 8:07 pm

This:

Code: Select all

on functionKey theKey
     switch
           case theKey = 11
               send "mouseUp" to button "BttF11"
               break
          case theKey = 12
               send "mouseUp" to button "BttF12"
               break
          default
               pass functionKey
     end switch     
end functionKey
will also work, spot the difference! :D

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: shortcut for function keys (F8;F9)[SOLVED]

Post by atout66 » Tue Apr 22, 2014 9:12 pm

Klaus, it's strange because to me it didn't work previously.
Now, I stop working but I'll test your code tomorrow.
Good night :wink:

Kind regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: shortcut for function keys (F8;F9)[SOLVED]

Post by Klaus » Wed Apr 23, 2014 6:09 am

Bonjour Jean-Paul.,
atout66 wrote:Klaus, it's strange because to me it didn't work previously.
my latest script of DIFFERENT ("spot the DIFFERENCE") than your first script! :D


Best

Klaus

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: shortcut for function keys (F8;F9)[SOLVED]

Post by atout66 » Wed Apr 23, 2014 9:55 am

@Klaus:
Ah, I see... you use "=" when I used "is", ie:
case theKey = 11(good) instead of
case theKey is 11(wrong), right ?

Thank you for your teachings :wink:

Kind regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

Post Reply