They know easily because as a foreigner you are required to carry your passport. And if you are not a tourist (again see your visa or stamp in your passport), you are required to have a Thai licence. Eg, Long term Visa or Retirement/ Marriage visa or extension then you are not a tourist.