Forum Navigation
You need to log in to create posts and topics.

Shortcut (key equivalent)

Posted by: bernfbe <bernfbe@...>


Working my way through Ari's nice utilities (welcome Ari!), I was wondering how he'd configured the user-preferred shortcut button (textfield?) in his Dusk app's preferences window.

Below is my attempt at emulating it. Improvements welcome.


btw, I wish I knew the unicode value for Apple's return key symbol. The one with the square hook.


/*
  Shortcut Button

  Click the button to make it the target for key presses.
  Click anywhere else to remove focus.
*/

_window = 1
begin enum 1
_shortcutLabel
_shortcutBtn
_clearBtn
end enum


void local fn BuildWindow
'~'1
subclass window _window, @"Shortcut", (0,0,480,360)

textlabel _shortcutLabel, @"Shortcut", (134,173,57,16)
subclass button _shortcutBtn,,, @"⌃⌘/", (190,163,100,32)

button _clearBtn,,, @"", (291,173,15,15)
ButtonSetBordered( _clearBtn, NO )
ButtonSetImage( _clearBtn, NSImageNameStopProgressFreestandingTemplate )
end fn


local fn CharacterForKeyCode( keyCode as unsigned short ) as CFStringRef
'~'1
CFStringRef chr = NULL

CFStringRef keyCodeCharacters = @"ASCFHGZXCVu00A7BQWERYT123465=97-80]OU[IPu21A9LJ'K;\,/NM.u21E5u2420`u232B"
select ( keyCode )
case 53  : chr = @"u241B" // esc
case 123 : chr = @"u25C0" // left arrow
case 124 : chr = @"u25B6" // right arrow
case 125 : chr = @"u25BC" // down arrow
case 126 : chr = @"u25B2" // up arrow
case else
if ( keyCode < len(keyCodeCharacters) )
chr = mid(keyCodeCharacters,keyCode,1)
end if
end select
end fn = chr


void local fn ShortcutBtnKeyDown
'~'1
NSEventModifierFlags modifiers = fn EventModifierFlags
unsigned short keyCode = fn EventKeyCode
CFStringRef string = fn CharacterForKeyCode( keyCode )
if ( string )
if ( modifiers and NSEventModifierFlagCommand ) then string = fn StringByAppendingString( @"⌘", string )
if ( modifiers and NSEventModifierFlagOption ) then string = fn StringByAppendingString( @"⌥", string )
if ( modifiers and NSEventModifierFlagControl ) then string = fn StringByAppendingString( @"⌃", string )
if ( modifiers and NSEventModifierFlagShift ) then string = fn StringByAppendingString( @"⇧", string )
button _shortcutBtn,,, string
end if
end fn


void local fn DoDialog( ev as long, tag as long, wnd as long )
'~'1
select ( ev )
case _btnClick
select ( tag )
case _clearBtn
button _shortcutBtn,,, @""
end select

case _viewMouseDown
select ( tag )
case _shortcutBtn
WindowMakeFirstResponder( _window, tag )
end select

case _viewKeyDown
select ( tag )
case _shortcutBtn
fn ShortcutBtnKeyDown
DialogEventSetBool(YES) // we handled
end select

case _windowMouseDown
select ( tag )
case _window
WindowMakeFirstResponder( _window, 0 )
end select
end select
end fn

fn BuildWindow

on dialog fn DoDialog

HandleEvents




--
To unsubscribe, send ANY message to: [email protected] To access the list archives, go to: http://freegroups.net/groups/futurebasic/