Assigning other key mapping instead of CmdPeriod

I realise CmdPeriod is a special class but is it possible to make other custom hotkey mappings in a class?

The editor handles hotkeys, not SC classes.

Look in the IDE preferences.


thanks for the info: I see that in the preferences you can reassign custom key bindings to the build-in actions – but how would I customise the actions then?
Say for this action to stop all MIDI in an IAC situation how would I configure that in the IDE? (or if not poss in IDE pref) use a different binding than CmdPeriod?

CmdPeriod.add({(0..127).do{arg n; m.noteOff(0, n)}});

Oh OK… the original question wasn’t quite clear. It seemed like you were asking about changing the keybinding for cmd-. (that’s in IDE preferences), but it seems like maybe you want to add something totally new which, like CmdPeriod, responds to a hotkey but which is separate from CmdPeriod.

With the IDE, it’s possible to use Document.globalKeyDownAction to implement new hotkeys. My ddwSnippets quark does this… here’s the bit that defines the key handler:

… and this bit installs the handler.

(I use a variable for the function, because I also wanted this class to be able to disable the hotkey – which requires a reference to the identical function object that was added. If you never want to disable the hotkey, you don’t have to worry about that – just Document.globalKeyDownAction = Document.globalKeyDownAction.addFunc { ...... } and go.) for details on the function arguments. Some of these get different values in different OSes – not a problem if you’re setting it up only for personal use.

Also, see these methods (of Integer) for testing specific modifier keys:

		// support for modifier 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 }


1 Like

Many thanks for this! It is exactly what I was after, incredibly helpful
– (also apologies it wasn’t the clearest initial query)