An electronic device (101; 401; 700), comprising: a chassis having an internal volume configured to house internal components of the electronic device; a button or an input/output interface positioned within an opening of the chassis, wherein the button or the input/output interface is configured to move from a first button position (114; 402) or first position to a second button position (304; 604) or second position upon application of an external force to the button or the input/output interface; a sensor in communication with the button or the input/output interface, wherein the button is configured to contact the sensor at an intermediate button position (206; 506) located between the first button position (114; 402) and the second button position (304; 604) or the input/output interface is configured to contact the sensor at the first position; and at least one magnet (124, 126; 406, 408) positioned within the internal volume of the chassis and configured to retain the sensor by a frictional or magnetic force (140; 418), characterized in that the sensor is configured to move from a first sensor position (142; 404; 704) to a second sensor position (306; 606); and the at least one magnet (124, 126; 406, 408) is configured to retain the sensor in the first sensor position (142; 404; 704) by the frictional or magnetic force (140; 418) when the button moves between the first button position (114; 402) and the intermediate button position (206; 506) or the input/output interface is located at the first position, and to release the sensor from the first sensor position (142; 404; 704) such that the sensor moves from the first sensor position to the second sensor position upon application of an external force (302; 602) greater than the frictional or magnetic force (140; 418) and less than a sensor damage force. a chassis having an internal volume configured to house internal components of the electronic device; a button or an input/output interface positioned within an opening of the chassis, wherein the button or the input/output interface is configured to move from a first button position (114; 402) or first position to a second button position (304; 604) or second position upon application of an external force to the button or the input/output interface; a sensor in communication with the button or the input/output interface, wherein the button is configured to contact the sensor at an intermediate button position (206; 506) located between the first button position (114; 402) and the second button position (304; 604) or the input/output interface is configured to contact the sensor at the first position; and at least one magnet (124, 126; 406, 408) positioned within the internal volume of the chassis and configured to retain the sensor by a frictional or magnetic force (140; 418), characterized in that the sensor is configured to move from a first sensor position (142; 404; 704) to a second sensor position (306; 606); and the at least one magnet (124, 126; 406, 408) is configured to retain the sensor in the first sensor position (142; 404; 704) by the frictional or magnetic force (140; 418) when the button moves between the first button position (114; 402) and the intermediate button position (206; 506) or the input/output interface is located at the first position, and to release the sensor from the first sensor position (142; 404; 704) such that the sensor moves from the first sensor position to the second sensor position upon application of an external force (302; 602) greater than the frictional or magnetic force (140; 418) and less than a sensor damage force.