Forum breadcrumbs - You are here:WeLoveGod RallysPublic Forums: futurebasicShortcut (key equivalent)
You need to log in to create posts and topics.
Shortcut (key equivalent)
77,940 Posts
#1 · February 10, 2022, 9:52 am
Quote from Forum Archives on February 10, 2022, 9:52 amPosted 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 ButtonClick the button to make it the target for key presses.Click anywhere else to remove focus.*/_window = 1begin enum 1_shortcutLabel_shortcutBtn_clearBtnend enumvoid local fn BuildWindow'~'1subclass 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 fnlocal fn CharacterForKeyCode( keyCode as unsigned short ) as CFStringRef'~'1CFStringRef chr = NULLCFStringRef keyCodeCharacters = @"ASCFHGZXCVu00A7BQWERYT123465=97-80]OU[IPu21A9LJ'K;\,/NM.u21E5u2420`u232B"select ( keyCode )case 53 : chr = @"u241B" // esccase 123 : chr = @"u25C0" // left arrowcase 124 : chr = @"u25B6" // right arrowcase 125 : chr = @"u25BC" // down arrowcase 126 : chr = @"u25B2" // up arrowcase elseif ( keyCode < len(keyCodeCharacters) )chr = mid(keyCodeCharacters,keyCode,1)end ifend selectend fn = chrvoid local fn ShortcutBtnKeyDown'~'1NSEventModifierFlags modifiers = fn EventModifierFlagsunsigned short keyCode = fn EventKeyCodeCFStringRef 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,,, stringend ifend fnvoid local fn DoDialog( ev as long, tag as long, wnd as long )'~'1select ( ev )case _btnClickselect ( tag )case _clearBtnbutton _shortcutBtn,,, @""end selectcase _viewMouseDownselect ( tag )case _shortcutBtnWindowMakeFirstResponder( _window, tag )end selectcase _viewKeyDownselect ( tag )case _shortcutBtnfn ShortcutBtnKeyDownDialogEventSetBool(YES) // we handledend selectcase _windowMouseDownselect ( tag )case _windowWindowMakeFirstResponder( _window, 0 )end selectend selectend fnfn BuildWindowon dialog fn DoDialogHandleEvents--
To unsubscribe, send ANY message to: [email protected] To access the list archives, go to: http://freegroups.net/groups/futurebasic/
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/
Click for thumbs down.0Click for thumbs up.0