I have the following structure:
class KeyboardModifiers(Structure):
_fields_ = [
('left_control', c_bool, 1),
('right_control', c_bool, 1),
('left_shift', c_bool, 1),
('right_shift', c_bool, 1),
('left_alt', c_bool, 1),
('right_alt', c_bool, 1),
('left_meta', c_bool, 1),
('right_meta', c_bool, 1),
('left_super', c_bool, 1),
('right_super', c_bool, 1),
('left_hyper', c_bool, 1),
('right_hyper', c_bool, 1),
]
It represents a structure returned by a C function, the fields are properly set and their values returned, issue comes when setting a field. For example, if I were to do something like:
my_keyboard_mods.left_shift = True
The first 8 fields would add be set to True, similarly with the next 8. What seems to happen is that it sets the value for the whole byte not respecting the bitfield. My question is:
- I am doing something wrong, so what’s wrong?
- This is a bug with ctypes, is there a workaround?
Thanks.