# How to color map keyswitches in Kontakt



## Maximvs (May 26, 2016)

Hello fellow Kontakt users,

I have a string sample library that unfortunately doesn't show the various active and temporary keyswitches by color in the actual Kontakt keyboard interface. Normally key switches are colored in red, green, yellow, etc. but for this library the only colored keys are the blue ones showing the actual instrument range.

I have heard that it is possible to color map keyswitches in Kontakt using scripting, unfortunately I do not have any knowledge in Kontak scripting and was wondering if there is a place where such a script can be purchased.

Thanks a lot in advance for any help and suggestions.

All the very best,

Max


----------



## Andreas Moisa (May 26, 2016)

I am only new to KSP but this is pretty easy, paste this into the script editor:

on init
set_key_color(24, $KEY_COLOR_RED)
end on

on note
message($EVENT_NOTE)
end on

You can change the number 24 to any key you want to color. You will get the number in the message bar when pressing your key.

Or if you want to color many keys at once use this:

on init
declare %key_switches [4] := (24,25,26,27)
declare $i := 0

while ($i < num_elements(%key_switches))
set_key_color(%key_switches[$i], $KEY_COLOR_BLUE)
inc($i)
end while
end on

on note
message($EVENT_NOTE)
end on


----------



## Maximvs (May 26, 2016)

Hello Andreas,

Thanks a lot for your kind reply!

If I want to color multiple keyswitches I assume that I will have to use the script multiple times and changing the "24 number" to reflect the not I want to color, correct?

If I want to change the color from "red" to say "green", I will just change that in the script under the "set_key_color"?

Another thing, I assume that I will have to do this for every string instrument patch and then re-save it, correct?

Best regards,

Max


----------



## Andreas Moisa (May 26, 2016)

Massimo said:


> If I want to color multiple keyswitches I assume that I will have to use the script multiple times and changing the "24 number" to reflect the not I want to color, correct?



Yes! Like this:

on init
set_key_color(24, $KEY_COLOR_RED)
set_key_color(25, $KEY_COLOR_RED)
end on



> If I want to change the color from "red" to say "green", I will just change that in the script under the "set_key_color"?



Yes again, the following colors are available:

$KEY_COLOR_RED
$KEY_COLOR_ORANGE
$KEY_COLOR_LIGHT_ORANGE
$KEY_COLOR_WARM_YELLOW
$KEY_COLOR_YELLOW
$KEY_COLOR_LIME
$KEY_COLOR_GREEN
$KEY_COLOR_MINT
$KEY_COLOR_CYAN
$KEY_COLOR_TURQUOISE
$KEY_COLOR_BLUE
$KEY_COLOR_PLUM
$KEY_COLOR_VIOLET
$KEY_COLOR_PURPLE
$KEY_COLOR_MAGENTA
$KEY_COLOR_FUCHSIA


----------



## Maximvs (May 26, 2016)

Thanks so much Andreas!

- I assume that I will have to do this for every string instrument patch and then re-save it, correct?

- In the even that there is already a script for a particular instrument patch, how do I go about incorporating this "keyswitch color mapping" script with the other script(s) so they don't conflict?

Many thanks again for your kind help, much appreciated!

Best regards,

Max


----------



## Andreas Moisa (May 26, 2016)

> I assume that I will have to do this for every string instrument patch and then re-save it, correct?



Yes.



> In the even that there is already a script for a particular instrument patch, how do I go about incorporating this "keyswitch color mapping" script with the other script(s) so they don't conflict?



Just use one of the five script slots that's free. Shouldn't be a problem.


----------



## Maximvs (May 26, 2016)

Thanks so much!

I really appreciate your kind help...

Take care,

Max


----------



## Maximvs (May 27, 2016)

Hello Andreas,

I have implemented the script that you kindly gave me yesterday and I have a question to ask you...

This is the script where I have added all the keyswitches I wanted to color in RED:
*
on init
declare %key_switches [17] := (24,25,26,27,28,29,30,31,33,36,38,40,42,47,48,49,50)
declare $i := 0

while ($i < num_elements(%key_switches))
set_key_color(%key_switches[$i], $KEY_COLOR_RED)
inc($i)
end while
end on

on note
message($EVENT_NOTE)
end on *

Now I would like to ask how can I include in this script other keyswitches in different colors like for example note number 32 colored Yellow, note 34 colored green, etc.

Thanks a lot in advance for your precious help!

Best regards,

Max


----------



## tonaliszt (May 28, 2016)

If you are not doing any more large amounts of key switches, you can just add them individually at the beginning. 

*on init

set_key_color(32, $KEY_COLOR_YELLOW)
set_key_color(34, $KEY_COLOR_GREEN)
declare %key_switches [17] := (24,25,26,27,28,29,30,31,33,36,38,40,42,47,48,49,50)
declare $i := 0*

etc..


----------



## Maximvs (May 29, 2016)

Thanks a lot n.h for your kind reply!

Best regards,

Max


----------



## audioeditor (Apr 14, 2020)

If one note is mapped across an octave, how do I set key color to the root note?


----------



## EvilDragon (Apr 14, 2020)

You just set_key_color(<MIDI note number>, <color you want>)


----------



## audioeditor (Apr 14, 2020)

EvilDragon said:


> You just set_key_color(<MIDI note number>, <color you want>)


Thank you. When you have 5 selectors, and for each selector, if I assigned one root note mapped on an octave, like the picture above..how is it possible to have different root notes colored?


----------



## EvilDragon (Apr 14, 2020)

Then you just use that command 5 times...


----------



## audioeditor (Apr 14, 2020)

Could you illustrate with an example?


----------



## EvilDragon (Apr 14, 2020)

Plenty of examples in this thread already...


----------



## scoobert12paws (Jul 31, 2020)

Andreas Moisa said:


> Yes! Like this:
> 
> on init
> set_key_color(24, $KEY_COLOR_RED)
> ...




Incredibly helpful thread! What is the Key Color to return a key to the default 'no color'?


----------



## polypx (Jul 31, 2020)

default and none are two different things:
KEY_COLOR_DEFAULT
KEY_COLOR_INACTIVE


----------

