This question has been answered by BobRay. See the first response.
$key = $modx->context->get('key');
Thanks Bob. Totally forgot about $modx->context$key = $modx->context->get('key');
This will set $key to the context key as a string (e.g., 'web').