Set cursor Location in edit box? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JackPJ
Posts: 18
Joined: 19 Oct 2016, 05:52

Set cursor Location in edit box?

07 Feb 2018, 09:55

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
}
Last edited by JackPJ on 07 Feb 2018, 11:11, edited 2 times in total.
JackPJ
Posts: 18
Joined: 19 Oct 2016, 05:52

Re: Set cursor Location in edit box?

07 Feb 2018, 10:09

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 :(
Guest

Re: Set cursor Location in edit box?

07 Feb 2018, 10:26

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
just me
Posts: 9449
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Set cursor Location in edit box?

07 Feb 2018, 10:35

You can get the position using RegExMatch() with a similar needle before RegExReplace().
JackPJ
Posts: 18
Joined: 19 Oct 2016, 05:52

Re: Set cursor Location in edit box?

07 Feb 2018, 11:08

Ahh, I get you,

thats perfect, thanks all

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ulysim and 310 guests