How can I ask for a password, replacing each keystroke with a generic character, on the command line of AutoCAD 2013 using ObjectARX?
Thanks in advance.
Solved! Go to Solution.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Thanks Alexander, but the solution in adndevblog fails in AutoCAD 2013. Look the comment by Thierry Prince below the solution.
Hi Jose,
Using hooks is a hack that is not generally advisable to use. If you have the option, switch over to a UI to take that input which you are trying to mask. That way you will not need to use hooks.
However if you still need to go this route, then here is a code snippet based on the low level keyboard hooks. Hope this helps. I havent tested it very extensively but seems to work in general using AutoCAD 2013.
Here is the sample code :
static ACHAR password[133]; static int pwdLen; static HHOOK hKeyboardHook; // - AdskMyTest1.MyCommand1 command (do not rename) static void AdskTestCommand(void) { ACHAR pwd[133]; adskGetPassword(1, ACRX_T("Password please ?"), pwd); } static int adskGetPassword(int cronly,ACHAR* prompt,ACHAR* result) { pwdLen = 0; password[pwdLen]='\0'; HINSTANCE hInstance = GetModuleHandle(NULL); if (!hInstance) return 1; hKeyboardHook = SetWindowsHookEx ( WH_KEYBOARD_LL, (HOOKPROC) KeyboardEvent, hInstance, NULL ); ACHAR tempResult[133]; int ret = acedGetString(cronly, prompt, tempResult); UnhookWindowsHookEx(hKeyboardHook); if(ret != RTNORM) acutPrintf(ACRX_T("\nCancelled.")); else { password[++pwdLen] = '\0'; acutPrintf(password); } wcscpy(result, password); return ret; } static LRESULT CALLBACK KeyboardEvent (int nCode, WPARAM wParam, LPARAM lParam) { if ((nCode == HC_ACTION) && ((wParam == WM_SYSKEYDOWN) || (wParam == WM_KEYDOWN))) { KBDLLHOOKSTRUCT hooked_key = *((KBDLLHOOKSTRUCT*)lParam); DWORD dwMsg = 1; dwMsg += hooked_key.scanCode << 16; dwMsg += hooked_key.flags << 24; int key = hs.vkCode; if ((key >= 'A' && key <= 'Z') || (key >= '0' && key <= '9')) { GetKeyNameText(dwMsg, &password[pwdLen], 0xFF) + 1; password[++pwdLen] = '\0'; keybd_event(VK_MULTIPLY, hooked_key.scanCode, hooked_key.flags, 0); return 1; } else if(hooked_key.vkCode == VK_BACK) { password[--pwdLen] = '\0'; } } return CallNextHookEx(hKeyboardHook, nCode,wParam,lParam); }
Thanks Balaji for your reply. The code works well with some corrections:
The line
int key = hs.vkCode;
must be
int key = hooked_key.vkCode;
and the line
GetKeyNameText(dwMsg, &password[pwdLen], 0xFF) + 1;
must be
GetKeyNameText(dwMsg, &password[pwdLen], 0xFF);
Can't find what you're looking for? Ask the community or share your knowledge.