This code works fine for the first slot in player inventory:
Minecraft mc = Minecraft.getMinecraft();
mc.playerController.windowClick(mc.player.inventoryContainer.windowId, 9, 0, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(mc.player.inventoryContainer.windowId, -999, 0, ClickType.PICKUP, mc.player);
The first instruction is the left mouse click (3° param is mouse click, 0 for left, 1 for right) on the first slot in player inventory (2° param is inventory slot (0-4 for crafting, 5-8 for armor, 9-35 for inventory)).
The second instruction is the left mouse click out of inventory GUI (to drop it down).
This code works fine with the inventory closed.