Well, detecting W is not necessary i think. If we attempt simple workarounds then multiplying current vehicle speed by a value between 0..1 should cause it to slow down. How much it slows down depends on how much it is drifting. Say car's angle being 90 degrees against its actual moving direction would cause highest slowdown.. (not sure, some 0.7x?), while moving in aligned direction 0 drift keeps multiplier at 1.0.
I didn't look at code but you probably have values for it already, just to rescale.
I suppose this would also fix the issue of car retaining full speed when turning even if there is no drifting mechanic, if it was an issue. IRL turning would always have a cost to speed anyway, even to trains if ever so slightly.