Page 1 of 1

Set cursor Location in edit box?

Posted: 07 Feb 2018, 09:55
by JackPJ
HI all,

I'm trying to move the cursor to the end of an edit box after my g-label triggers and removes the non-"a-z0-9" characters.

currently, the G-label triggers, removes the * from the string, and updates the editbox. but the cursor is back at the start of the box.

I know I could end the g-label with something like "Send ^{right}" to go to the end, but I feel like this is bodging it and opens me up for an unknown case causing issues later on.

Any help would be appreciated!

Thanks

SOLUTION

for anyone else with this issue:

Code: Select all

Gui, 2:add, Edit, x5 y5 h20   w150  vAddEditVehicleRegistration1 gAddEditVehicleRegistration1 limit10, 
gui, 2:show h100 y200 
return



AddEditVehicleRegistration1:
{
	GuiControlGet, temp,,AddEditVehicleRegistration1
	tempCursorPos := RegExMatch(temp, "[^a-zA-Z0-9]") - 1
	if (tempCursorPos >= 0)
	{
		temp := RegExReplace(temp, "[^a-zA-Z0-9]", "")
		;~ MsgBox,,,%tempCursorPos%
		GuiControl, 2:-g, AddEditVehicleRegistration1
		GuiControl, 2:, AddEditVehicleRegistration1, %temp%
		temphwnd := xgc.hwnd
		SendMessage, 0xB1, %tempCursorPos%, %tempCursorPos%,,ahk_id %temphwnd%
		GuiControl, 2:+gAddEditVehicleRegistration1, AddEditVehicleRegistration1
	}
	return
}

Re: Set cursor Location in edit box?  Topic is solved

Posted: 07 Feb 2018, 10:01
by Guest
See the two SendMessage commands in the second post here https://autohotkey.com/boards/viewtopic.php?f=5&t=23000

Re: Set cursor Location in edit box?

Posted: 07 Feb 2018, 10:09
by JackPJ
Thanks,

I just realised I worded my question poorly and didn't cover all options, I'd ideally like to keep the cursor wherever it is when the text gets removes. i.e if I went back to a box that has "123456789" and entered a % in the middle like "12345%6789"
I'd still want my cursor to stay in the same place (between 5 and 6).

your example was great for selecting a final position, but how would I get the current cursor location?

I'm guessing the regexreplace I'm using must know the position of the first symbol it removes? how would I find it?

sorry, I suck with regex :(

Re: Set cursor Location in edit box?

Posted: 07 Feb 2018, 10:26
by Guest
In that case (and any other Edit control "needs") I can only recommend you have a look (and use) the Edit library by jballi which includes getting/setting selections, positions, find/replace etc:
https://autohotkey.com/boards/viewtopic.php?f=6&t=5063

Re: Set cursor Location in edit box?

Posted: 07 Feb 2018, 10:35
by just me
You can get the position using RegExMatch() with a similar needle before RegExReplace().

Re: Set cursor Location in edit box?

Posted: 07 Feb 2018, 11:08
by JackPJ
Ahh, I get you,

thats perfect, thanks all