Assigning a keyboard shortcut to a button
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Assigning a keyboard shortcut to a button
Hey!
I'm a total beginner - not experienced at all in coding but I've been fiddeling around with Live Code for quite some time now and got my first few applications up and running.
One thing that I wasn't quite able to figure out is the following:
I have a couple of buttons that I'd like to be activated (on mousedown functions inside...) via the press of a keyboard key, or combination of keys (e.g. Strg + Alt + e) in addition to the 'on mouse down'-action. I am using an external USB input device fires those keyboard 'macros' on button press, but I don't know how to tell my Live Code buttons how to detect inputs other than 'mouse down'.
I stumbled upon the 'keyDown' function but can't seem to make it work the same way as the 'on mouse down' function.
Any help or nudge in the right direction is highly appreciated
Thanks in advance!
Bambster
I'm a total beginner - not experienced at all in coding but I've been fiddeling around with Live Code for quite some time now and got my first few applications up and running.
One thing that I wasn't quite able to figure out is the following:
I have a couple of buttons that I'd like to be activated (on mousedown functions inside...) via the press of a keyboard key, or combination of keys (e.g. Strg + Alt + e) in addition to the 'on mouse down'-action. I am using an external USB input device fires those keyboard 'macros' on button press, but I don't know how to tell my Live Code buttons how to detect inputs other than 'mouse down'.
I stumbled upon the 'keyDown' function but can't seem to make it work the same way as the 'on mouse down' function.
Any help or nudge in the right direction is highly appreciated
Thanks in advance!
Bambster
Re: Assigning a keyboard shortcut to a button
You didn't mention which version of Lc your working in, but regardless what you are looking for can be handled directly in the properties window, by setting the 'accelKey' property.
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Assigning a keyboard shortcut to a button
Hi,
I think you have to use keysdown function
The keysDown function returns a list of keycodes of pressed keys, separated by commas if more than one key is being pressed.
Something like that:
end mousedown
You may get the keycode of a touch with this on card script
Best regards
Jean-Marc
I think you have to use keysdown function
The keysDown function returns a list of keycodes of pressed keys, separated by commas if more than one key is being pressed.
Something like that:
Code: Select all
on mousedown
if the optionkey is down and the keysdown = 101,0 then
answer "optionkey is down and you press e" -- e = 101
else
"nothing happened"
end if
You may get the keycode of a touch with this on card script
Code: Select all
on rawkeydown pKey
put pKey
end rawkeydown
Jean-Marc
https://alternatic.ch
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Assigning a keyboard shortcut to a button
Here's a way to do this:
The button "Button F1" contains this script:
The card contains this script:
The button "Button F1" contains this script:
Code: Select all
on mouseUp
put "You just clicked on button Button F1."
end mouseUp
Code: Select all
on rawKeyUp RUP
if RUP = 65470 then
send "mouseUp" to btn "Button F1"
else
pass rawKeyUp
end if
end rawKeyUp
-
- VIP Livecode Opensource Backer
- Posts: 9840
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Assigning a keyboard shortcut to a button
If you want to provide visual feedback for the action the keyboard shortcut triggers, you can use "click at the loc of button..." instead of "send...", so the button will momentarily highlight like it would if clicked.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Assigning a keyboard shortcut to a button
Hi Bogs,
I have forgotten this way but I can't find accelKey in my object inspector (LC indy 8.1.6, OS X)
Best
Jean-Marc
I have forgotten this way but I can't find accelKey in my object inspector (LC indy 8.1.6, OS X)
Best
Jean-Marc
https://alternatic.ch
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Assigning a keyboard shortcut to a button
First off: the possibility of assigning keystrokes seems to have either been "deprecated"
(why do I dislike that word so much?) or, at least, made inaccessible.
Secondly: what "ancient" flavour of LiveCode was your screen snap from,
as in 7.1.4 the thing is called a "shortcut" and not an "accelKey"?
I just performed some archaeology and found that the Props palette for RunRev 4.0 uses "shortcut".
Oddly enough so does RunRev 2.2.1 (Linux).
Maybe that's a Windows 'thing'
Last edited by richmond62 on Thu Mar 29, 2018 7:59 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Assigning a keyboard shortcut to a button
Aha: one can set an accelKey via code in LiveCode 8.1.8.
I expect in LiveCode's efforts to make LiveCode 8.1.8 easier for new learners they hid that feature away.
I expect in LiveCode's efforts to make LiveCode 8.1.8 easier for new learners they hid that feature away.
Re: Assigning a keyboard shortcut to a button
Yah, it has been called different things over the releases, figures that something ridiculously easy and useful would be ripped out for some obscure reason. Progress!richmond62 wrote: ↑Thu Mar 29, 2018 7:41 pmFirst off: the possibility of assigning keystrokes seems to have either been "deprecated"
(why do I dislike that word so much?) or, at least, made inaccessible.
Well, when I go poking around for something and I want it fast my default is 6.5.2. Funny you should mention 2.x, I was diddling around with that beaut a lot yesterday, you want to talk about features I find refreshing to have, that one has it in spades. If only I could get it to load faster, it would probably replace 6.5.2 and MC as my default goto buttonSecondly: what "ancient" flavour of LiveCode was your screen snap from,
BITE YOUR TONGUE! Why, even mentioning such is almost BLASPHEMOUS in my caseMaybe that's a Windows 'thing'
Last edited by bogs on Thu Mar 29, 2018 8:42 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Assigning a keyboard shortcut to a button
Among many other ways I have made myself popular with LiveCode and the "choir" is by repeatedlythat one has it in spades
suggesting a bit of a slowdown (sometimes chasing hell-for-leather after new features means old ones that need a bit of polishing get disregarded) and even the odd backward step.
Re: Assigning a keyboard shortcut to a button
You and I are apparently in the same choir. It is what probably keeps making it less desirable to dl the newest versions at all (for me, mind you I am a distinct minority I think).
Re: Assigning a keyboard shortcut to a button
Okay, wow. This is basically all I was trying to do. Thank you so much!richmond62 wrote: ↑Thu Mar 29, 2018 6:51 pmHere's a way to do this:
BPress.png
The button "Button F1" contains this script:The card contains this script:Code: Select all
on mouseUp put "You just clicked on button Button F1." end mouseUp
Button Press.livecode.zipCode: Select all
on rawKeyUp RUP if RUP = 65470 then send "mouseUp" to btn "Button F1" else pass rawKeyUp end if end rawKeyUp
Adding key combinations would be a nice plus though, since this would help prevent accidental key presses, but for now this really is all I needed.
Also big thanks to all the others contributors!
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Assigning a keyboard shortcut to a button
Much as I have tried, all my life, I have never managed to sing in tune.You and I are apparently in the same choir
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Assigning a keyboard shortcut to a button
In the cardScript:Adding key combinations would be a nice plus though
Code: Select all
on rawKeyUp RUP
if the shiftKey is down then
if RUP = 65470 then
send "mouseUp" to btn "Button Shift + F1"
else
pass rawKeyUp
end if
else
if RUP = 65470 then
send "mouseUp" to btn "Button F1"
else
pass rawKeyUp
end if
end if
end rawKeyUp
Re: Assigning a keyboard shortcut to a button
Hi,
"Property labels are:"
"Description of option" => "Shortcut"
"Name of LC property" => "accelKey"
And yes, they omitted it completely in the 8 versions prop palette. Who needs keyboard shortcuts in "apps", anyways?
Have fun!
This depends of the setting in the preferences:richmond62 wrote: ↑Thu Mar 29, 2018 7:41 pm[...] the thing is called a "shortcut" and not an "accelKey"? [...]
"Property labels are:"
"Description of option" => "Shortcut"
"Name of LC property" => "accelKey"
And yes, they omitted it completely in the 8 versions prop palette. Who needs keyboard shortcuts in "apps", anyways?
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!