Welcome to the forums @"Bohang Zhang"!
You probably need to use casting, and then check if you get a null pointer or not, based on my C++ experience with Godot source code. Something like this should work, I think:
InputEventKey *potential_key = Object::cast_to<InputEventKey>(InputEventVariableHere);
if (potential_key):
// You have a InputEventKey! Do stuff here.
Though it looks like the syntax for GDNative is slightly different than in Godot source, based on this GitHub issue.
So, to adapt the above code to GDNative, you'd need something like this:
godot::InputEventKey *potential_key = godot::Object::cast_to<godot::InputEventKey>(InputEventVariableHere);
if (potential_key):
// You have a InputEventKey! Do stuff here.