Fix bugs in APIs enterstring() and generatekeyevent()