Space Bar [Solved]
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Space Bar [Solved]
Hi there,
I have a really simple question. If I want to refer to the space bar in a script, how do I do that? I've figured out the on keydown function, but I can't find anything in the reference material about how to specify the space bar!
Thanks in advance
I have a really simple question. If I want to refer to the space bar in a script, how do I do that? I've figured out the on keydown function, but I can't find anything in the reference material about how to specify the space bar!
Thanks in advance
Last edited by symiant on Fri Jan 16, 2015 6:37 pm, edited 1 time in total.
Space bar
Hi Symiant,
You can try this :
Regards
Jean-Marc
You can try this :
Code: Select all
on keydown pLetter
if pLetter = " " then
doMyScript
end if
end keydown
Jean-Marc
There are a couple of variants you can investigate, keyDown and rawKeyDown. In keyDown the character is sent with the message, and space can be tested using the Rev built in constant "space" :
rawKeyDown will send the raw key code value, which for space will be 32:
There are other messages for return, enter, tab etc. The rawKeyDown handler will be especially useful for things like mouse-wheel scrolling, etc.
HTH.
Nice one Jean-Marc, just got in while I was copy pasting my script snippets!
Code: Select all
on keyDown theKey
if theKey is space then
put "You pressed space"
end if
pass keydown
end keyDown
Code: Select all
on rawKeyDown theRawKey
if theRawKey is 32 then
put "Space bar pressed"
end if
pass rawkeydown
end rawKeyDown
HTH.
Nice one Jean-Marc, just got in while I was copy pasting my script snippets!

Last edited by SparkOut on Mon Jul 13, 2009 1:59 pm, edited 1 time in total.
-
- Posts: 344
- Joined: Tue Feb 24, 2009 6:14 pm
- Contact:
Re: Space Bar
I also happen to have a really simple answer. If you want to refer to the space bar in a script, you do that by using the keyword space. You've figured out the on keyDown function, so you can specify the space bar by still using the space keyword.symiant wrote:Hi there,
I have a really simple question. If I want to refer to the space bar in a script, how do I do that? I've figured out the on keydown function, but I can't find anything in the reference material about how to specify the space bar!
Thanks in advance

-
- Posts: 344
- Joined: Tue Feb 24, 2009 6:14 pm
- Contact:
Re: Space Bar
Greetings everyone.
I'm having some problems with the keyDown message...
What I have:
- I have a group of objects that I would like to scroll using mouse drag over the group with the aid of a key pressed by the user
What I did:
- I was able to scroll the group using drag and drop by following this simple tutorial (check runrev lesson: 44421-how-to-create-a-scrolling-group-using-the-improved-graphics-architecture)
What I want:
- i want to be able to scroll the group when the user is pressing the SPACEBAR and he is drag & dropping inside the group area
on so, what have i don .. i have modified the simple drag & drop script to only scroll if the SPACEBAR is pressed.
however, it seems the system doesn't even recognizes that i'm pressing the key.
Heres the code in caso someone could give me an help.
Note: this code is added to the group
Can anyone give me some hint?
Thanks in advance
- Miguel
I'm having some problems with the keyDown message...
What I have:
- I have a group of objects that I would like to scroll using mouse drag over the group with the aid of a key pressed by the user
What I did:
- I was able to scroll the group using drag and drop by following this simple tutorial (check runrev lesson: 44421-how-to-create-a-scrolling-group-using-the-improved-graphics-architecture)
What I want:
- i want to be able to scroll the group when the user is pressing the SPACEBAR and he is drag & dropping inside the group area
on so, what have i don .. i have modified the simple drag & drop script to only scroll if the SPACEBAR is pressed.
however, it seems the system doesn't even recognizes that i'm pressing the key.
Heres the code in caso someone could give me an help.
Note: this code is added to the group
Code: Select all
local sScrolling
local sInitialMouseX, sInitialMouseY
local sInitialHScroll, sInitialVScroll
on keyDown theKey
answer theKey
if theKey is space then
//answer "SPACE SPACE SPACE"
put true into sScrolling
end if
pass keydown
end keyDown
on keyUp theKey
if theKey is space then
put false into sScrolling
end if
end keyUp
on mouseDown
## Allow the group to scroll
##put true into sScrolling
## Record the initial touch position
put item 1 of the mouseLoc into sInitialMouseX
put item 2 of the mouseLoc into sInitialMouseY
## Record the initial hScroll and vScroll
put the vScroll of me into sInitialVScroll
put the hScroll of me into sInitialHScroll
end mouseDown
on mouseMove mouseX, mouseY
## If the screen is being touched then
if sScrolling then
## Calculate how far the touch has moved since it started
put mouseY - sInitialMouseY into tVChange
put mouseX- sInitialMouseX into tHChange
## Reset the hScroll and vScroll to follow the touch
lock screen
set the vScroll of me to sInitialVScroll - tVChange
set the hScroll of me to sInitialHScroll - tHChange
unlock screen
end if
end mouseMove
Thanks in advance
- Miguel
Re: Space Bar
Hi.
You are confusing a message with a function. When you press a key, like the spacebar, several messages are sent, which you can trap and process. But you cannot use the spacebar in the same way as, say, the commandKey or the optionKey.
There is no "spaceBarKey" function native to LiveCode, as there is, say, to "optionKey"
So you cannot test if "the spaceBarKey is down". All your problems will go away if you move your thinking to one of the control keys that do have this native function available, like command,option, shift, capsLock or control.
BUT, if you are intent on the spacebar, you may want to look at the "keysDown" function. This will allow you to check the state of any key at all, including spacebar.
Craig Newman
You are confusing a message with a function. When you press a key, like the spacebar, several messages are sent, which you can trap and process. But you cannot use the spacebar in the same way as, say, the commandKey or the optionKey.
There is no "spaceBarKey" function native to LiveCode, as there is, say, to "optionKey"
So you cannot test if "the spaceBarKey is down". All your problems will go away if you move your thinking to one of the control keys that do have this native function available, like command,option, shift, capsLock or control.
BUT, if you are intent on the spacebar, you may want to look at the "keysDown" function. This will allow you to check the state of any key at all, including spacebar.
Craig Newman
Re: Space Bar
Actually, space should work okay in the script. The keydown/keyup messsages recognize the constant "space".
The problem may be that the field isn't focused. If the user hasn't clicked on the field or something else hasn't put it in focus, the keydown message will not be sent to the field, it will be sent to the card or to whatever other field might have focus at that moment. If there are no other controls on the card that need to trap keydowns, then a handler in the card script can manage the scrolling instead of a script in the field itself.
To see if that's the problem, try clicking on the field first before scrolling with the spacebar. If that works, move the script to the card.
The problem may be that the field isn't focused. If the user hasn't clicked on the field or something else hasn't put it in focus, the keydown message will not be sent to the field, it will be sent to the card or to whatever other field might have focus at that moment. If there are no other controls on the card that need to trap keydowns, then a handler in the card script can manage the scrolling instead of a script in the field itself.
To see if that's the problem, try clicking on the field first before scrolling with the spacebar. If that works, move the script to the card.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Space Bar
OK, to archive what I want .. partially lol 
There's something not working right but I'm not getting what (i have attached the example and code if anyone want to check)
I have put the "space down" verification in the Stack code
Then, on the group code I have placed the drag & drop scroll code that sill only be enabled IF the spacebar is being pressed.
I first tried to make something like a on*off switch. i click space to activate the scroll, and then i can scroll with drag & drop. Then if i click space again, the scroll is disabled and i cannot scroll.
This worked fine. The problem is when i try to do it while the space is being pressed. It works a little bit then stops working. Them i release and press the space again and it works a little bit again and stops again.
Any ideas/suggestions?
I also noticed something weird: if you create an "on keyDown theKey" handler with something like "answer theKey" and is you execute and hold a letter key, the answer dialog will open once and won't open again until you press a new letter. if you press the spacebar, the dialog will appear and disappear continuously while you are pressing the space.

There's something not working right but I'm not getting what (i have attached the example and code if anyone want to check)
I have put the "space down" verification in the Stack code
Then, on the group code I have placed the drag & drop scroll code that sill only be enabled IF the spacebar is being pressed.
I first tried to make something like a on*off switch. i click space to activate the scroll, and then i can scroll with drag & drop. Then if i click space again, the scroll is disabled and i cannot scroll.
This worked fine. The problem is when i try to do it while the space is being pressed. It works a little bit then stops working. Them i release and press the space again and it works a little bit again and stops again.
Any ideas/suggestions?
I also noticed something weird: if you create an "on keyDown theKey" handler with something like "answer theKey" and is you execute and hold a letter key, the answer dialog will open once and won't open again until you press a new letter. if you press the spacebar, the dialog will appear and disappear continuously while you are pressing the space.
- Attachments
-
- Untitled 1.zip
- my example andcode
- (17.74 KiB) Downloaded 351 times
Re: Space Bar
Okay, I see. In that case Craig was right, you can't test for the space key that way. He understood what you wanted better than I did. Do what he suggested and use the option or command key, or some other control key that has a built-in function to test whether it is pressed or not.
The reason you are getting multiple responses for the spacebar is because as long as you hold it down, the OS key repeat kicks in and it is sent repeatedly until you let go. The control keys don't do that, they only have "up" or "down" states.
The reason you are getting multiple responses for the spacebar is because as long as you hold it down, the OS key repeat kicks in and it is sent repeatedly until you let go. The control keys don't do that, they only have "up" or "down" states.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Space Bar
hmmm they why this doenst happen with letter keys for example? the space key is special in this matter ?
ill try with control key then.
Do i use the keyDown handler too? can you give me an example please?
Many thanks
- Miguel
ill try with control key then.
Do i use the keyDown handler too? can you give me an example please?
Many thanks
- Miguel
Re: Space Bar
ok ... i think i did it (yeh! ) 
but i really REALLY wanted to make this with the space bar (like in Adobe Illustrator)
There's really no way do do it with space?
thank you for your help guys
cheers
- Miguel

but i really REALLY wanted to make this with the space bar (like in Adobe Illustrator)

There's really no way do do it with space?
thank you for your help guys
cheers
- Miguel