ObjectARX

ObjectARX

Reply
Active Member
JoseVicario
Posts: 6
Registered: ‎08-20-2012
Message 1 of 5 (307 Views)
Accepted Solution

How to ask for a password on the command line of AutoCAD 2013 using ObjectARX?

307 Views, 4 Replies
10-06-2012 12:35 AM

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.

Moderator
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 2 of 5 (297 Views)

Re: How to ask for a password on the command line of AutoCAD 2013 using ObjectAR

10-06-2012 02:58 AM in reply to: JoseVicario

Try this: http://adndevblog.typepad.com/autocad/2012/06/asking-for-a-password-on-the-command-line-of-autocad-u...


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Member
JoseVicario
Posts: 6
Registered: ‎08-20-2012
Message 3 of 5 (292 Views)

Re: How to ask for a password on the command line of AutoCAD 2013 using ObjectAR

10-06-2012 05:34 AM in reply to: Alexander.Rivilis

Thanks Alexander, but the solution in adndevblog fails in AutoCAD 2013. Look the comment by Thierry Prince below the solution.

ADN Support Specialist
Balaji_Ram
Posts: 691
Registered: ‎03-21-2011
Message 4 of 5 (249 Views)

Re: How to ask for a password on the command line of AutoCAD 2013 using ObjectAR

10-13-2012 09:36 AM in reply to: JoseVicario

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);
}

 



Balaji
Developer Technical Services
Autodesk Developer Network

Active Member
JoseVicario
Posts: 6
Registered: ‎08-20-2012
Message 5 of 5 (237 Views)

Re: How to ask for a password on the command line of AutoCAD 2013 using ObjectAR

10-13-2012 11:05 AM in reply to: Balaji_Ram

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);

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.