KeyUp Head Scratcher

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
xfratboy
Posts: 97
Joined: Fri Mar 05, 2010 9:09 pm

KeyUp Head Scratcher

Post by xfratboy » Sat Aug 07, 2010 4:29 pm

I have not been able to resolve a strange dilemma. I'm trying to handle keyUp to perform a task of increase/decrease graphic size. When the "i" key is pressed the graphic increases in size, "d" key = decrease. This works fine, but for some reason after pressing i or d keys, the subsequent pressing of any special keys (enter, shift, alt, numlock, arrows, capslock) seems to trigger the increase/decrease handle. I'm guessing there's just something simple I'm not understanding about the message path or keyUp. What's weird is that if I press the TAB key after pressing I or D key it seems to release the message handle. See attached stack. To duplicate,
1) press i or d key
2) then press any special key and the handle icreaseObjSize or DecreaseObjSize handle will fire.
3) press tab and special keys no longer trigger the the handle until I or D is pressed again.

Code: Select all

on keyUP tKey 
   if tKey is "i" then
      increaseObjSize
   end if
   if tKey is "d" then
      DecreaseObjSize
   End if
end keyUP

on increaseObjSize
   put the height of graphic theObject  into tempH
   put the width of graphic theObject  into tempW
   if tempH >400 or tempW >400 then exit increaseObjSize
   set the height of graphic theObject to tempH +2
   set the width of graphic theObject to tempW +2
end increaseObjSize

on DecreaseObjSize
   put the height of graphic theObject  into tempH
   put the width of graphic theObject  into tempW
   if tempH <11 or tempW <8 then exit decreaseObjSize
   set the height of graphic theObject to tempH -2
   set the width of graphic theObject to tempW -2
end DecreaseObjSize
Attachments
keyUpProblem.zip
(688 Bytes) Downloaded 228 times

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: KeyUp Head Scratcher

Post by Dixie » Sat Aug 07, 2010 7:18 pm

xfratboy ...

I downloaded your stack and ran it... I am not seeing any of the problems you mention. The size of the graphic only increases or decreases with the pressing of the 'i' or 'd' key... no other keys alter the graphic size

be well

Dixie

Mac 10.6.4. Rev 4.0

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: KeyUp Head Scratcher

Post by bn » Sat Aug 07, 2010 7:40 pm

xfratboy,

I see the same as Dixie does, same operating system, same Rev version.

Hi Dixie.

Maybe it is some Windows related behaviour?

I would put this on a keyDown or rawKeyDown handler, because when I press a key I like to see what happens and not after I release the key. If you put it on a rawkeyDown handler you have the advantage that keeping the key pressed repeats the action. Also when changing the size of an object be careful not to change the location of the object.

Code: Select all

on rawkeyDown tKey
   if tKey is 105 then
      increaseObjSize
   end if
   if tKey is 100 then
      DecreaseObjSize
   end if
end rawkeyDown


on increaseObjSize
   put the loc of graphic "theObject" into tWhere
   put the height of graphic "theObject"  into tempH
   put the width of graphic "theObject"  into tempW
   if tempH >400 or tempW >400 then exit increaseObjSize
   
   put 2 into tHowMuch
   if the optionKey is down then put 5 into tHowMuch  -- altKey
   
   lock screen
   set the height of graphic "theObject" to tempH + tHowMuch
   set the width of graphic "theObject" to tempW + tHowMuch
   set the loc of graphic "theObject" to tWhere
end increaseObjSize


on DecreaseObjSize
   put the loc of graphic "theObject" into tWhere
   put the height of graphic "theObject"  into tempH
   put the width of graphic "theObject"  into tempW
   if tempH <11 or tempW <8 then exit decreaseObjSize
   put 2 into tHowMuch
   if the optionKey is down then put 5 into tHowMuch  -- altKey
   
   
   lock screen
   set the height of graphic "theObject" to tempH - tHowMuch
   set the width of graphic "theObject" to tempW - tHowMuch
   set the loc of graphic "theObject" to tWhere
end DecreaseObjSize
I added a condition for the altKey on windows or optionKey on the Mac (just two different names for the same key) then it in/decreases by 5 or whatever you set it to.

regards
Bernd

Post Reply