Quantcast

Integer modifier keys

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Integer modifier keys

LightRate
Does anyone recognize this code at the bottom of Integer.sc ?

// support for modifiers keys
isCaps { ^this.bitAnd(65536) == 65536}
isShift { ^this.bitAnd(131072) == 131072 }
isCtrl { ^this.bitAnd(262144) == 262144 }
isAlt { ^this.bitAnd(524288) == 524288 }
isCmd { ^this.bitAnd(1048576) == 1048576 }
isNumPad { ^this.bitAnd(2097152) == 2097152 }
isHelp { ^this.bitAnd(4194304) == 4194304 }
isFun { ^this.bitAnd(8388608) == 8388608 }


How would someone use these numbers? Do they somehow allow us to write code that is functionally consistent across all platforms? Without using something like:

Platform.case
{
        \windows
}{
        // do Windows command
}
{
        \osx
}{
        // do OSX equivalent of Windows command
}

Thanks in advance, I'm just looking for the most basic idea about what these numbers mean and how to use them.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Integer modifier keys

ddw_music
LightRate wrote
// support for modifiers keys
isCaps { ^this.bitAnd(65536) == 65536}
isShift { ^this.bitAnd(131072) == 131072 }
isCtrl { ^this.bitAnd(262144) == 262144 }
isAlt { ^this.bitAnd(524288) == 524288 }
isCmd { ^this.bitAnd(1048576) == 1048576 }
isNumPad { ^this.bitAnd(2097152) == 2097152 }
isHelp { ^this.bitAnd(4194304) == 4194304 }
isFun { ^this.bitAnd(8388608) == 8388608 }
You have to use them in a function that receives keystrokes -- and that's only in GUI views and Documents.

Quick example:

b = Button(nil, Rect(800, 200, 100, 20))
.states_([["type"]])
.keyDownAction_({ |view, char, mods|
        #[isCaps, isShift, isCtrl, isAlt, isCmd, isNumPad, isHelp, isFun].do { |check|
                if(mods.perform(check)) { "got %\n".postf(check) };
        };
})
.front;

hjh
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Integer modifier keys

alberto.decampo
there is a helpfile called Modifier Keys that explains it, but it seems that needs an update for qt, which has the QModifierKey class for that.
best adc

> On Jan 4, 2017, at 08:49, ddw_music <[hidden email]> wrote:
>
> LightRate wrote
>> // support for modifiers keys
>> isCaps { ^this.bitAnd(65536) == 65536}
>> isShift { ^this.bitAnd(131072) == 131072 }
>> isCtrl { ^this.bitAnd(262144) == 262144 }
>> isAlt { ^this.bitAnd(524288) == 524288 }
>> isCmd { ^this.bitAnd(1048576) == 1048576 }
>> isNumPad { ^this.bitAnd(2097152) == 2097152 }
>> isHelp { ^this.bitAnd(4194304) == 4194304 }
>> isFun { ^this.bitAnd(8388608) == 8388608 }
>
> You have to use them in a function that receives keystrokes -- and that's
> only in GUI views and Documents.
>
> Quick example:
>
> b = Button(nil, Rect(800, 200, 100, 20))
> .states_([["type"]])
> .keyDownAction_({ |view, char, mods|
>    #[isCaps, isShift, isCtrl, isAlt, isCmd, isNumPad, isHelp, isFun].do {
> |check|
>        if(mods.perform(check)) { "got %\n".postf(check) };
>    };
> })
> .front;
>
> hjh
>
>
>
> --
> View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Integer-modifier-keys-tp7629977p7629978.html
> Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Loading...