Positioning the cursor
Positioning the cursor
Hi
How do I force Positioning the cursor in a specific String box when I press the tab key?
Thank you
How do I force Positioning the cursor in a specific String box when I press the tab key?
Thank you
Re: Positioning the cursor
Do you mean whenever the user tabs into your StringGadget specifically, or around the app in general?
As far as setting the cursor goes, that really depends on your platform. On Windows, for example, you'd do something like:
As far as setting the cursor goes, that really depends on your platform. On Windows, for example, you'd do something like:
Code: Select all
SendMessage_(GadgetID(#Gadget), #EM_SETSEL, startpos, endpos)
Re: Positioning the cursor
The most simpliest and cross-platform if I've well understood your request:
@Quin
At first, I thought too that was the request, but I'm not sure.
Code: Select all
If OpenWindow(0, 0, 0, 322, 205, "Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0, 8, 10, 306, 20, "")
StringGadget(1, 8, 35, 306, 20, "")
StringGadget(2, 8, 60, 306, 20, "")
AddKeyboardShortcut(0,#PB_Shortcut_Tab,500)
Repeat
Event= WaitWindowEvent()
Select Event
Case #PB_Event_Menu
Select EventMenu()
Case 500
Select GetActiveGadget()
Case 0:NewGadget=2
Case 2:NewGadget=1
Default:NewGadget=0
EndSelect
SetActiveGadget(NewGadget)
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
At first, I thought too that was the request, but I'm not sure.

If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Except on this sentence...
Re: Positioning the cursor
I started reconsidering too after I made my first post. The wording is slightly ambiguousboddhi wrote: Sat Sep 14, 2024 7:13 pm @Quin
At first, I thought too that was the request, but I'm not sure.![]()
@OP, would you mind telling us a bit more about what you're actually trying to do here?
Re: Positioning the cursor
This may be a solution
Code: Select all
;{ this is part of code maked by Axoloti here: https://www.purebasic.fr/english/viewtopic.php?t=85314
Macro IsKeyPressed(VirtualKey) ; BOOL .. on #VK_SHIFT, #VK_CONTROL, etc.
Bool(GetAsyncKeyState_(VirtualKey) & $8000)
EndMacro
;}
;{
winMain= OpenWindow(#PB_Any,0,0,960,540,"TAB was a drink?",#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
For p= 1 To 5
StringGadget(p,10,15+p*35,200,25,"String "+Str(p))
Next p
Repeat
event= WindowEvent()
Select event
Case #PB_Event_Gadget
EventGadget= EventGadget()
EventType= EventType()
Select EventGadget
Case 0
EndSelect
Case #PB_Event_CloseWindow
Break
EndSelect
If IsKeyPressed(#VK_TAB) And release <> #VK_TAB
release=#VK_TAB
ElseIf IsKeyPressed(#VK_TAB)=0 And release= #VK_TAB
release= 0
Debug "TAB active gadget 4"
SetActiveGadget(4)
EndIf
Delay(1)
ForEver
;}
If translation=Error: reply="Sorry, Im Spanish": Endif
Re: Positioning the cursor
For Windows
Code: Select all
LoadFont(0,"Georgia",16)
OpenWindow(0,0,0,600,200,"Control TABSTOPS",#PB_Window_SystemMenu | #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered)
StringGadget(0,10,10,580,30,"", #ES_MULTILINE )
Dim tabStops.i(4)
tabStops(0) = 12
tabStops(1) = 36
tabStops(2) = 80
tabStops(3) = 140
SendMessage_(GadgetID(0),#EM_SETTABSTOPS,ArraySize(tabStops()),@tabStops())
SetGadgetFont(0,FontID(0))
SetActiveGadget(0)
AddKeyboardShortcut(0,#PB_Shortcut_Tab,10)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Menu
Select EventMenu()
Case 10
If GetActiveGadget() = 0
SendMessage_(GadgetID(0),#WM_CHAR,9,0)
EndIf
EndSelect
EndSelect
Until Quit = 1
End
Egypt my love
Re: Positioning the cursor
Expanding on @boddhi's example, the tab order can be arranged as required:
And here, in a different order:
And here, with reverse tabbing using the Shift-Tab key combination:
Code: Select all
#stringTab = 99
window = OpenWindow(#PB_Any, 0, 0, 590, 220, "Textbox Tab Order",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
; sequential order
s1 = StringGadget(#PB_Any, 30, 30, 150, 30, "1. first tab")
s2 = StringGadget(#PB_Any, 220, 30, 150, 30, "2. second tab")
s3 = StringGadget(#PB_Any, 410, 30, 150, 30, "3. third tab")
; reverse order
s4 = StringGadget(#PB_Any, 30, 90, 150, 30, "6. sixth tab ")
s5 = StringGadget(#PB_Any, 220, 90, 150, 30, "5. fifth tab")
s6 = StringGadget(#PB_Any, 410, 90, 150, 30, "4. fourth tab")
; sequential order
s7 = StringGadget(#PB_Any, 30, 150, 150, 30, "7. seventh tab")
s8 = StringGadget(#PB_Any, 220, 150, 150, 30, "8. eighth tab")
s9 = StringGadget(#PB_Any, 410, 150, 150, 30, "9. ninth tab")
AddKeyboardShortcut(window ,#PB_Shortcut_Tab, #stringTab)
SetGadgetData(s1, s2) ; from string 1 jump to string 2
SetGadgetData(s2, s3) ; from string 2 jump to string 3
SetGadgetData(s3, s6) ; from string 3 jump to string 6
SetGadgetData(s4, s7) ; from string 4 jump to string 7
SetGadgetData(s5, s4) ; from string 5 jump to string 4
SetGadgetData(s6, s5) ; from string 6 jump to string 5
SetGadgetData(s7, s8) ; from string 7 jump to string 8
SetGadgetData(s8, s9) ; from string 8 jump to string 9
SetGadgetData(s9, s1) ; from string 9 jump to string 1
SetActiveGadget(s1)
Repeat
event= WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
appQuit = #True
Case #PB_Event_Menu
Select EventMenu()
Case #stringTab
nextTab = GetGadgetData(GetActiveGadget())
SetActiveGadget(nextTab)
EndSelect
EndSelect
Until appQuit
And here, in a different order:
Code: Select all
#stringTab = 99
window = OpenWindow(#PB_Any, 0, 0, 590, 220, "Textbox Tab Order",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
s1 = StringGadget(#PB_Any, 30, 30, 150, 30, "1. first tab")
s2 = StringGadget(#PB_Any, 220, 30, 150, 30, "6. sixth tab ")
s3 = StringGadget(#PB_Any, 410, 30, 150, 30, "7. seventh tab")
s4 = StringGadget(#PB_Any, 30, 90, 150, 30, "2. second tab")
s5 = StringGadget(#PB_Any, 220, 90, 150, 30, "5. fifth tab")
s6 = StringGadget(#PB_Any, 410, 90, 150, 30, "8. eighth tab")
s7 = StringGadget(#PB_Any, 30, 150, 150, 30, "3. third tab")
s8 = StringGadget(#PB_Any, 220, 150, 150, 30, "4. fourth tab")
s9 = StringGadget(#PB_Any, 410, 150, 150, 30, "9. ninth tab")
AddKeyboardShortcut(window ,#PB_Shortcut_Tab, #stringTab)
SetGadgetData(s1, s4) ; from string 1 jump to string 4
SetGadgetData(s2, s3) ; from string 2 jump to string 3
SetGadgetData(s3, s6) ; from string 3 jump to string 6
SetGadgetData(s4, s7) ; from string 4 jump to string 7
SetGadgetData(s5, s2) ; from string 5 jump to string 2
SetGadgetData(s6, s9) ; from string 6 jump to string 9
SetGadgetData(s7, s8) ; from string 7 jump to string 8
SetGadgetData(s8, s5) ; from string 8 jump to string 5
SetGadgetData(s9, s1) ; from string 9 jump to string 1
SetActiveGadget(s1)
Repeat
event= WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
appQuit = #True
Case #PB_Event_Menu
Select EventMenu()
Case #stringTab
nextTab = GetGadgetData(GetActiveGadget())
SetActiveGadget(nextTab)
EndSelect
EndSelect
Until appQuit
And here, with reverse tabbing using the Shift-Tab key combination:
Code: Select all
#stringTabForward = 98
#stringTabBackward = 99
Dim tabs(9, 1)
window = OpenWindow(#PB_Any, 0, 0, 590, 220, "Textbox Tab Order",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(1, 30, 30, 150, 30, "1. first tab")
StringGadget(2, 220, 30, 150, 30, "2. second tab")
StringGadget(3, 410, 30, 150, 30, "3. third tab")
StringGadget(4, 30, 90, 150, 30, "6. sixth tab ")
StringGadget(5, 220, 90, 150, 30, "5. fifth tab")
StringGadget(6, 410, 90, 150, 30, "4. fourth tab")
StringGadget(7, 30, 150, 150, 30, "7. seventh tab")
StringGadget(8, 220, 150, 150, 30, "8. eighth tab")
StringGadget(9, 410, 150, 150, 30, "9. ninth tab")
AddKeyboardShortcut(window ,#PB_Shortcut_Tab, #stringTabForward)
AddKeyboardShortcut(window ,#PB_Shortcut_Shift | #PB_Shortcut_Tab, #stringTabBackward)
tabs(1, 0) = 2 : tabs(1, 1) = 9 ; string 1 forwards to string 2 and reverses to string 9
tabs(2, 0) = 3 : tabs(2, 1) = 1 ; string 2 forwards to string 3 and reverses to string 1
tabs(3, 0) = 6 : tabs(3, 1) = 2 ; string 3 forwards to string 6 and reverses to string 2
tabs(4, 0) = 7 : tabs(4, 1) = 5 ; string 4 forwards to string 7 and reverses to string 5
tabs(5, 0) = 4 : tabs(5, 1) = 6 ; string 5 forwards to string 4 and reverses to string 6
tabs(6, 0) = 5 : tabs(6, 1) = 3 ; string 6 forwards to string 5 and reverses to string 3
tabs(7, 0) = 8 : tabs(7, 1) = 4 ; string 7 forwards to string 8 and reverses to string 4
tabs(8, 0) = 9 : tabs(8, 1) = 7 ; string 8 forwards to string 9 and reverses to string 7
tabs(9, 0) = 1 : tabs(9, 1) = 8 ; string 9 forwards to string 1 and reverses to string 8
SetActiveGadget(1)
Repeat
event= WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
appQuit = #True
Case #PB_Event_Menu
Select EventMenu()
Case #stringTabForward
nextTab = tabs(GetActiveGadget(), 0)
SetActiveGadget(nextTab)
Case #stringTabBackward
prevTab = tabs(GetActiveGadget(), 1)
SetActiveGadget(prevTab)
EndSelect
EndSelect
Until appQuit
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

Re: Positioning the cursor
Combining the two @TI-944 examples (
) and considering the use of enumeration (as strongly recommended by the PB team) and/or gadget numbers lower than 65535:


Code: Select all
#stringTabForward = 98
#stringTabBackward = 99
window = OpenWindow(#PB_Any, 0, 0, 590, 220, "Textbox Tab Order",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(1, 30, 30, 150, 30, "1. first tab")
StringGadget(2, 220, 30, 150, 30, "2. second tab")
StringGadget(3, 410, 30, 150, 30, "3. third tab")
StringGadget(4, 30, 90, 150, 30, "6. sixth tab ")
StringGadget(5, 220, 90, 150, 30, "5. fifth tab")
StringGadget(6, 410, 90, 150, 30, "4. fourth tab")
StringGadget(7, 30, 150, 150, 30, "7. seventh tab")
StringGadget(8, 220, 150, 150, 30, "8. eighth tab")
StringGadget(9, 410, 150, 150, 30, "9. ninth tab")
;SetGadgetData(GadgetNr, Tab gadget << 16 + ShiftTab gadget)
SetGadgetData(1, 2 << 16 + 9) ; string 1 forwards to string 2 and reverses to string 9
SetGadgetData(2, 3 << 16 + 1) ; string 2 forwards to string 3 and reverses to string 1
SetGadgetData(3, 6 << 16 + 2) ; string 3 forwards to string 6 and reverses to string 2
SetGadgetData(4, 7 << 16 + 5) ; string 4 forwards to string 7 and reverses to string 5
SetGadgetData(5, 4 << 16 + 6) ; string 5 forwards to string 4 and reverses to string 6
SetGadgetData(6, 5 << 16 + 3) ; string 6 forwards to string 5 and reverses to string 3
SetGadgetData(7, 8 << 16 + 4) ; string 7 forwards to string 8 and reverses to string 4
SetGadgetData(8, 9 << 16 + 7) ; string 8 forwards to string 9 and reverses to string 7
SetGadgetData(9, 1 << 16 + 8) ; string 9 forwards to string 1 and reverses to string 8
AddKeyboardShortcut(window ,#PB_Shortcut_Tab, #stringTabForward)
AddKeyboardShortcut(window ,#PB_Shortcut_Shift | #PB_Shortcut_Tab, #stringTabBackward)
SetActiveGadget(1)
Repeat
event= WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
appQuit = #True
Case #PB_Event_Menu
Select EventMenu()
Case #stringTabForward
SetActiveGadget(GetGadgetData(GetActiveGadget()) >> 16)
Case #stringTabBackward
DataGadget = GetGadgetData(GetActiveGadget())
SetActiveGadget(DataGadget - (DataGadget >> 16) << 16)
; or in one line :
;SetActiveGadget(GetGadgetData(GetActiveGadget()) - (GetGadgetData(GetActiveGadget()) >> 16) << 16)
EndSelect
EndSelect
Until appQuit
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Except on this sentence...
- Mindphazer
- Enthusiast
- Posts: 456
- Joined: Mon Sep 10, 2012 10:41 am
- Location: Savoie
Re: Positioning the cursor
Nice example ! 

MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
...and unfortunately... Windows at work...
Re: Positioning the cursor
Hi
Thank You all
I got it working, Just design the gadjet one after the other.
The idea is to havave the cursor jumping from gadjet to the next gadjet when we press the tab key
Thak You
Thank You all
I got it working, Just design the gadjet one after the other.
The idea is to havave the cursor jumping from gadjet to the next gadjet when we press the tab key
Thak You
Re: Positioning the cursor
Only on Windows. macOS and Linux do not conform to the order of the gadget declarations.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

Re: Positioning the cursor
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive