There is no certain way to determine if someone remotely viewed your Mac. If you suspect someone is using your Mac without your permission, then change its login password. Consider changing your Apple ID password as well, since it can be used to reset a login password.
To learn how to do that please read the following Apple Support documents.
Set up your Mac to be secure - Apple Support
Keep your Apple ID secure - Apple Support
What are privacy laws if someone did it by breaking into the code of MacOS without my permission.
Apple Support Communities is not a legal service. In most jurisdictions, unauthorized tampering with computing equipment is a crime. You will need to consult with your local law enforcement agencies, Attorney General's office, or other appropriate legal counsel for answers to those questions.
"Breaking into the code" needs explanation. Inspecting computer operating system code is not a crime.
My keyboard brightness button works one time with F1 where as on pressing F2, the brightness increases automatically. Is it according to MacOS design.
The F1 and F2 keys decrease and increase display brightness, respectively. Touching any key causes the keyboard to illuminate under low ambient light. To learn how to use a Mac please read Get started with your Mac - Apple Support.