As of the 1.40 update, players were allowed to add Keys into courses.
Keys can be placed in blocks, or in an enemy, such as making them obtainable after Mario defeats it. Thus, this also makes some enemies having to be defeated in order to procceed through the level. After obtaining the key, the player has to bring it to a Key Door and unlock it. A key doesn't need to be directly held onto by Mario, as it just automatically follows him after obtaining it, functioning similarly to the keys in the Yoshi's Island series. Up to eight keys can be obtained at one time. You get it by shaking a P-switch.
Keys can be dragged onto enemies, and the enemy will drop the key when killed. If it is a circle of Boo Buddies, all the boos must be defeated to get the key. If a key is put into a question block or brick block, the key will be obtained when broken in any way, unlike every other item. If a key is put in a Yoshi egg, the egg will hatch into a key.
Additionally, another new item included in the update, the Pink Coin, reveals a key once Mario collects every single one in the level.