Extract common function for input method.