If it is an apple branded smart keyboard, and it is giving an error message of accessory not supported, check and make sure the smart connector pins are free of any dirt or debris. If they are, you need to go to an apple retail store, or apple authorized service provider to have the device inspected.
Good Luck