Skip to main content

Keyboard Commands

get_key_color()

get_key_color(<note-nr>)

Returns the color constant of the specified note number

Examples

on init
	message("")
	declare $count
	while ($count < 128)
		set_key_color($count,$KEY_COLOR_INACTIVE)
		inc($count)
	end while
	
	declare $random_key
	$random_key := random(60,71)
	
	set_key_color($random_key,$KEY_COLOR_RED)
	
end on

on note
	if (get_key_color($EVENT_NOTE) = $KEY_COLOR_RED)
		message("Bravo!")
		
		set_key_color($random_key,$KEY_COLOR_INACTIVE)
		$random_key := random(60,71)
		set_key_color($random_key,$KEY_COLOR_RED)
	else
		message("Try again!")
	end if
end on

on release
	message("")
end on

Catch me if you can

See Also

set_key_color()

get_key_name()

get_key_name(<note-nr>)

Returns the name of the specified key

Examples

on init
    
    declare $count
    while ($count < 128)
        set_key_name($count,"")
        inc($count)
    end while
    
	set_key_name(60,"Middle C")

end on

on note
	message(get_key_name($EVENT_NOTE))
end on

See Also

set_key_name()

get_key_triggerstate()

get_key_triggerstate(<note-nr>)

Returns the pressed state of the specified note number, i.e. key, on the KONTAKT keyboard. It can be either 1 (key pressed) or 0 (key released).

Remarks

  • get_key_triggerstate() only works with set_key_pressed_support() set to 1.

Examples

on init
    set_key_pressed_support(1)
end on
on note
    set_key_pressed($EVENT_NOTE,1)
    message(get_key_triggerstate($EVENT_NOTE))
end on
on release
    set_key_pressed($EVENT_NOTE,0)
    message(get_key_triggerstate($EVENT_NOTE))
end on

See Also

set_key_pressed()

set_key_pressed_support()

get_key_type()

get_key_type(<note-nr>)

Returns the key type constant of the specified key

See Also

set_key_type()

get_keyrange_min_note()

get_key_type(<note-nr>)

Returns the lowest note of the specified key range

Remarks

  • Since a key range cannot have overlapping notes, it is sufficient with all get_keyrange_xxx() commands to specify the key range with one note number only.

Examples

on init
    
    declare $count
    while ($count < 128)
      
        remove_keyrange($count)
        inc($count)
    end while
   
    set_keyrange(36,72,"Middle Range")
   
end on

on note
	message(get_keyrange_min_note($EVENT_NOTE))
end on

See Also

set_keyrange()

get_keyrange_max_note()

get_keyrange_max_note(<note-nr>) 

Returns the highest note of the specified key range

Remarks

  • Since a key range cannot have overlapping notes, it is sufficient with all get_keyrange_xxx() commands to specify the key range with one note number only.

Examples

on init
    
    declare $count
    while ($count < 128)
      
        remove_keyrange($count)
        inc($count)
    end while
   
    set_keyrange(36,72,"Middle Range")
   
end on

on note
	message(get_keyrange_min_note($EVENT_NOTE))
end on

See Also

set_keyrange()

get_keyrange_name()

get_keyrange_name(<note-nr>)

Returns the name of the specified key range

Remarks

  • Since a key range cannot have overlapping notes, it is sufficient with all get_keyrange_xxx() commands to specify the key range with one note number only.

Examples

on init
    
    declare $count
    while ($count < 128)
      
        remove_keyrange($count)
        inc($count)
    end while
    
    set_keyrange(36,72,"Middle Range")
   
end on

on note
	message(get_keyrange_name($EVENT_NOTE))
end on

See Also

set_keyrange()

set_key_color()

set_key_color(<note-nr>,<key-color-constant>)

Sets the color of the specified key, i.e. MIDI note, on the KONTAKT keyboard.

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

$KEY_COLOR_DEFAULT sets the key to KONTAKT's standard color for mapped notes

$KEY_COLOR_INACTIVE resets the key to standard black and white

$KEY_COLOR_NONE resets the key to its normal KONTAKT color, e.g. red for internal keyswitches

Remarks

  • The keyboard colors reside outside of KSP, i.e. changing the color of a key is similar to changing a KONTAKT knob with set_engine_par(). It is therefore a good practice to set all keys to either $KEY_COLOR_INACTIVE or $KEY_COLOR_NONE in the init callback or whenever changed later.

Example

on init
	message("")
	declare ui_button $Color
	
	declare $count
	declare $note_count
	declare $color_count
	declare %white_keys[7] := (0,2,4,5,7,9,11)
	declare %colors[16] := (...
	$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)
	
	$count := 0
	while ($count < 128)
		set_key_color($count,$KEY_COLOR_NONE)
		inc($count)
	end while
end on

on ui_control ($Color)
	if ($Color = 1)
		
		$count := 0
		while ($count < 128)
			set_key_color($count,$KEY_COLOR_INACTIVE)
			inc($count)
		end while
	
		$note_count := 0
		$color_count := 0
		while ($color_count < 16)
			
			if (search(%white_keys,(60 + $note_count) mod 12) # -1)
				set_key_color(60 + $note_count,%colors[$color_count])
				inc ($color_count)
			end if
			
			inc($note_count)
		
		end while
		
	else
		
		$count := 0
		while ($count < 128)
			set_key_color($count,$KEY_COLOR_NONE)
			inc($count)
		end while
		
	end if
			
end on

KONTAKT rainbow

See Also

set_control_help()

get_key_color()

set_key_name()

set_keyrange()

set_key_name()

set_key_name(<note-nr>,<name>)

Assigns a text string to the specified key

Remarks

  • Key names are instrument parameters and reside outside KSP, i.e. changing the key name is similar to changing a KONTAKT knob with set_engine_par(). Make sure to always reset all key names in the init callback or whenever changed later.

  • Key names and ranges are displayed in KONTAKT's info pane when hovering the mouse over the key on the KONTAKT keyboard.

Examples

on init
    
    declare $count
    while ($count < 128)
        set_key_name($count,"")
        inc($count)
    end while
    
	set_key_name(60,"Middle C")

end on

See Also

set_keyrange()

get_key_name()

set_key_pressed()

set_key_pressed(<note-nr>,<value>)

Sets the trigger state of the specified key on KONTAKT's keyboard either to pressed/on (1) or released/off (0).

Remarks

  • By using set_key_pressed() in combination with set_key_pressed_support() it is possible to show script generated notes on KONTAKT's keyboard. The typical use case would be if an instrument features a built-in sequencer/harmonizer and the triggered notes should be shown on the keyboard.

Examples

on init
    set_key_pressed_support(1)
end on
on note
    set_key_pressed($EVENT_NOTE,1)
end on
on release
    set_key_pressed($EVENT_NOTE,0)
end on

Insert this after an arpeggiator or harmonizer script

See Also

set_key_pressed_support()

get_key_triggerstate()

set_key_pressed_support()

set_key_pressed_support(<mode>) 

Sets the pressed state support mode for KONTAKT'S keyboard. The available modes are:

0: KONTAKT handles all pressed states. set_key_pressed() commands are ignored (default mode).

1: KONTAKT's keyboard is only affected by set_key_pressed()commands.

Remarks

  • The pressed state mode resides outside KSP, i.e. changing the mode is similar to changing a KONTAKT knob with set_engine_par(). Make sure to always set the desired mode in the init callback.

Examples

on init
    declare ui_button $Enable
    set_key_pressed_support(0)
end on

on ui_control ($Enable)
	set_key_pressed_support($Enable)
end on

on note
	play_note($EVENT_NOTE+4,$EVENT_VELOCITY,0,-1)
	play_note($EVENT_NOTE+7,$EVENT_VELOCITY,0,-1)
 	set_key_pressed($EVENT_NOTE,1)
	set_key_pressed($EVENT_NOTE+4,1)
	set_key_pressed($EVENT_NOTE+7,1)
end on

on release
	set_key_pressed($EVENT_NOTE,0)
	set_key_pressed($EVENT_NOTE+4,0)
	set_key_pressed($EVENT_NOTE+7,0)
end on

Press the button and you will see what you hear

See Also

set_key_pressed()

get_key_triggerstate()

set_key_type()

set_key_type(<note-nr>,<key-type-constant>) 

Assigns a key type to the specified key.

The following key types are available:

$NI_KEY_TYPE_DEFAULT i.e. normal mapped notes that produce sound.

$NI_KEY_TYPE_CONTROL i.e. key switches or other notes that do not produce sound.

$NI_KEY_TYPE_NONE resets the key to its normal KONTAKT behaviour.

Remarks

  • Setting the key type is useful for supported hosts like KOMPLETE KONTROL, where keys with control functionality, e.g. key switches, should not be affected by any note processing.

Examples

on init
    
    declare $count
    
    $count := 0
    while ($count < 128)
        set_key_type($count,$NI_KEY_TYPE_NONE)
        inc($count)
    end while
    
    $count := 36
    while ($count <= 96)
        
        select ($count)
            
            case 36 to 47 {e.g. key switch}
                set_key_type($count,$NI_KEY_TYPE_CONTROL)
            
            case 48 to 96 {e.g. main notes}
                set_key_type($count,$NI_KEY_TYPE_DEFAULT)
                
        end select
        
        inc($count)
    end while
end on

See Also

get_key_type()

set_keyrange()

set_keyrange(<min-note>,<max-note>,<name>) 

Assigns a text string to the specified range of keys

Remarks

  • Key ranges are instrument parameters and reside outside KSP, i.e. changing the key range is similar to changing a KONTAKT knob with set_engine_par(). Make sure to always remove all key ranges in the init callback or whenever changed later.

  • There can be up to 16 key ranges per instrument.

  • Key names and ranges are displayed in KONTAKT's info pane when hovering the mouse over the key on the KONTAKT keyboard. The range name is followed by the key name, separated by a dash.

Examples

on init
    
    declare $count
    while ($count < 128)
      
        remove_keyrange($count)
        inc($count)
    end while
    
    set_keyrange(36,72,"Middle Range")
   
end on

See Also

remove_keyrange()

set_key_name()

remove_keyrange()

remove_keyrange(<note-nr>) 

Assigns a text string to the specified range of keys

Remarks

  • Key ranges are instrument parameters and reside outside KSP, i.e. changing the key range is similar to changing a KONTAKT knob with set_engine_par(). Make sure to always remove all key ranges in the init callback or whenever changed later.

Examples

on init
    
    declare $count
    while ($count < 128)
      
        remove_keyrange($count)
        inc($count)
    end while
    
    set_keyrange(36,72,"Middle Range")
   
end on

See Also

set_keyrange()