Friday, November 24, 2017

#1 2009-10-26 09:26:33 pm

robdut
Member
Registered: 2009-09-02
Posts: 301

Key down no longer works on Snow Leopard

Hi all,

I have been spending most of my time over on the Applescript OBJ-C list but am trying meanwhile to keep my ASS app alive on Snow Leopard.

I have a table in a split view that has a key down event handler

Applescript:

on keyboard down theObject event theEvent
   log theEvent
   if name of theObject = "backups" then
   set theKeyPressed to (key code of theEvent)
   log theKeyPressed
if theKeyPressed = 51 then
--process rows to remove
end
   end if
end keyboard down

This previously worked fine in leopard and earlier. Now I get the error:

2009-10-26 21:57:44.448 backuplist+[1999:903] *** Assertion failure in -[NSEvent keyCode], /SourceCache/AppKit/AppKit-1038.11/AppKit.subproj/NSEvent.m:1901
2009-10-26 21:57:44.448 backuplist+[1999:903] An exception was thrown during execution of an NSScriptCommand...
2009-10-26 21:57:44.448 backuplist+[1999:903] Invalid message sent to event "NSEvent: type=Timer loc=(700,653) time=0.0 flags=0x100 win=0x0 winNum=0 ctxt=0xe1d3 subtype=0 data1=0 data2=0"

it logs theEvent as event 1 but there is no way to get key code or anything else out of it. I saw an earlier post about this and double clicked handler and wonder if anyone has since found a way to get a key code in SNow Leopard.

Thanks,  Rob D

Offline

 

#2 2009-10-29 12:48:18 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5179

Re: Key down no longer works on Snow Leopard

Not that it's likely to be of much help, but that log entry suggests you're not actually getting a keyboard event. The only events that have subtype, data1 and data2 methods are NSAppKitDefined, NSSystemDefined, and NSApplicationDefined, according to the docs.

I suppose it's always possible that you're trapping extra events, and the events you want are still in the queue -- you could test this out by putting the attempt to get the key code in a try/end try, or if that doesn't work, check the type of the event.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2010-08-17 08:26:14 pm

dwm
Member
Registered: 2005-07-15
Posts: 2

Re: Key down no longer works on Snow Leopard

Hi;

I usually come here for tips, so I hope this is useful to others.

I had the same issue show up in an app I was updating for Snow Leopard. And had the "Assertion failure . . . . " errors too, and this fix stopped it. The "key code of theEvent" was failing no matter how I tried to use it.

The fix for this is to enable the Delete menu item in the Edit menu in the main nib (or add it if not present) and assign the Delete key (Backspace on Macs) to it. In Interface Builder's Attributes Inspector, assign the Delete key to it by simply clicking in the Key Equiv. box and pressing the Delete key.

In the code example below when the Edit menu Delete item is selected or the Delete key  pressed, the code is executed. In my app the delete key is used only to delete list items, hence the name assigned to it in Interface Builder is "deleteListItem".

Applescript:


--// menu item choices //--
on choose menu item theObject

   set menuName to name of theObject

   if menuName is "deleteListItem" then
       my deleteListItem()
       return
   end if

If you don't want to use the Edit menu Delete item another way is to use "on clicked" in the interface and a modifier key such as Command, Option or Control key. In the code example below "event 1" passes the key event to the handler as follows.

Applescript:


on clicked objectClicked

   set objName to name of objectClicked
   if option key down of event 1 then set optionKey to true
       
   --// list functions //--
   if objName is "sheetsTable" and optionKey then
       my deleteListItem()
       return
   end if

Many thanks to all that contribute here, this is my 4th year with a commercial app in distribution.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)