Blocking a key for most uses

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gjn1w07
Posts: 17
Joined: Mon Mar 31, 2008 3:59 pm

Blocking a key for most uses

Post by gjn1w07 » Wed Apr 02, 2008 9:58 am

I'm writing an application where there are effectively two tasks going on. One task involves writing answers to questions in various boxes. At the same time another task involves listening to numbers being read out and pressing a key when 3 odd numbers are heard in a row.

My question is can I block out one key so that it ONLY, say, puts a 1 in a variable and does nothing else? What I'm aiming for here is a key that doesn't interfere with the person's responding to the questions when they press it. For instance if it were the space bar I was to use, I wouldn't want lots of random spaces being inserted into their answers.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Apr 02, 2008 10:15 am

Dear gjn1w07,

How doesn't this answer your question?

http://forums.runrev.com/phpBB2/viewtop ... ight=#6331

Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

gjn1w07
Posts: 17
Joined: Mon Mar 31, 2008 3:59 pm

Post by gjn1w07 » Wed Apr 02, 2008 11:22 am

That was a slightly different question, hence the seperate thread. That did answer my original question, which was just "how do I use the space bar in the code"

This question is how do I for instance, have the "g" key ONLY put 1 into the variable tGPressed, and not pass the fact that it has been pressed to any other field? So for instance if the user was in a text entry box typing in the word "hello" and pressed the g key in the middle of typing, I want the g key press to put 1 into the variable tGPressed without actually typing a g. So if a user pressed g in the middle of typing hello, it ends up as "hello" and not "helglo". In effect I want to disable the key for all but one use for the card.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Apr 02, 2008 11:30 am

Dear gjn1w07,

The script is still the same as in the other thread:

Code: Select all

on keyUp theKey
  if theKey = <some character> then
    --do stuff here
  end if
end keyUp
If you want to take several different keys into account, just add some if-then statements:

Code: Select all

on keyUp theKey
  if theKey = <some character> then
    --do stuff here
  if theKey = <some other character> then
    --do other stuff here
  else
    pass keyUp
  end if
end keyUp
Make sure to put any characters in quotes.

Kindest regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Wed Apr 02, 2008 10:59 pm

To interrupt keys, you need the keydown message, without passing it. Look at these documentation entries:

keyDown message
keyUp message
pass control structure
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

gjn1w07
Posts: 17
Joined: Mon Mar 31, 2008 3:59 pm

Post by gjn1w07 » Thu Apr 03, 2008 11:16 am

Thanks for all that. I now see how this is working. Cheers all!

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Thu Apr 03, 2008 9:14 pm

Would rawKeyDown and rawKeyUp be better to use?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Apr 03, 2008 9:26 pm

Hi Garrett,

If you know that you want to "catch" a specific character, the space bar or e.g. a question mark, keyUp and keyDown are sufficient. RawKeyUp and rawKeyDown are slightly more complex and useful if you want a script to respond to the backspace key, the delete key, escape key, et cetera. Nonetheless it is possible to use rawKeyUp instead of rawKeyDown if you need to.

Btw, BvG is right about keyDown, of course, if you don't want the "g" to be put into the field you're typing in. I wonder how one would write "good morning" though ;-)

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Thu Apr 03, 2008 9:32 pm

They work differently. The rawKey messages use numbers, the same ones as the keysdown() function. The key messages use the chars themselves.

This means that all characters that can't be typed into the script editor as a string, will not be usable with the key messages. A good example is the return key, you can't just type that into a string in the script editor, therefore it only works with the rawKey messages.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Fri Apr 04, 2008 8:29 am

Ahhh.. got ya. Thanks. :-)

Post Reply