I'm looking to display a soft keyboard for use with ImGui in a unity game, and I know that Open method in the class TouchScreenKeyboard can help me to do that. But when I try to call Open the game crashes. I tried referring to related post but I still can't fix it.
My code:
I try like this:
My code:
C++:
enum class TouchScreenKeyboardType {
Default,
ASCIICapable,
NumbersAndPunctuation,
URL,
NumberPad,
PhonePad,
NamePhonePad,
EmailAddress,
NintendoNetworkAccount,
Social,
Search,
DecimalPad
};
enum class Status {
Visible,
Done,
Canceled,
LostFocus,
};
struct IntPtr {
void *m_value;
};
class TouchScreenKeyboard {
public:
IntPtr m_Ptr;
bool get_active() {
bool (*get_active_)(TouchScreenKeyboard *keyboard) = (bool (*)(TouchScreenKeyboard *))Method("UnityEngine.CoreModule.dll", "UnityEngine", "TouchScreenKeyboard", "get_active", 0);
return get_active_(this);
}
Status get_status() {
Status (*get_status_)(TouchScreenKeyboard *keyboard) = (Status (*)(TouchScreenKeyboard *))Method("UnityEngine.CoreModule.dll", "UnityEngine", "TouchScreenKeyboard", "get_status", 0);
return get_status_(this);
}
String *get_text() {
String *(*get_text_)(TouchScreenKeyboard *keyboard) = (String *(*)(TouchScreenKeyboard *))Method("UnityEngine.CoreModule.dll", "UnityEngine", "TouchScreenKeyboard", "get_text", 0);
return get_text_(this);
}
static TouchScreenKeyboard *Open(String *text, TouchScreenKeyboardType keyboardType, bool autocorrection, bool multiline, bool secure, bool alert, String *textPlaceholder, int characterLimit) {
TouchScreenKeyboard *(*Open_)(String *text, TouchScreenKeyboardType keyboardType, bool autocorrection, bool multiline, bool secure, bool alert, String *textPlaceholder, int characterLimit) = (TouchScreenKeyboard *(*)(String *, TouchScreenKeyboardType, bool, bool, bool, bool, String *, int))Method("UnityEngine.CoreModule.dll", "UnityEngine", "TouchScreenKeyboard", "Open", 8);
return Open_(text, keyboardType, autocorrection, multiline, secure, alert, textPlaceholder, characterLimit);
}
};
I try like this:
C++:
ImGui::Begin("Test", nullptr);
if (ImGui::Button("Click Me")) {
TouchScreenKeyboard *Keyboard = TouchScreenKeyboard::Open(Il2CppString::Create(""), TouchScreenKeyboardType::Default, false, false, false, false, Il2CppString::Create(""), 100);
}
ImGui::End();
Last edited: