Tab between textfields... How?

BlitzPlus Forums/BlitzPlus Programming/Tab between textfields... How?

Sin of Nature(Posted 2004) [#1]
Hi,

Want to be able to press tab whilst a textfield is active. This will then jump to the next text field... and so on. The problem is that I everytime I try do this the tab key simply beeps. Anyone done this already?

What is the correct way of determining what was the last key pressed in the textfield? (preferrably without simply readying it from the textfieldtext command. I've replaced it with a star for a password so that method is no use).

Sin


Kevin_(Posted 2004) [#2]
Unfortunately you cannot TAB between textfields. Why? I dont know. Its been requested many times.

Use eventsource() and the handle of your textfield then use eventdata() to get the keypress.

Hope that helps


Beaker(Posted 2004) [#3]
You can do it but its not pretty, and a bit complicated to explain. [EDIT: syntax error must've had more sleep than me - see below]


EOF(Posted 2004) [#4]
You can 'tab' between text fields usings HotKeyEvent and a couple of API calls.
In this example the GetFocus() is used to find which gadget is currently active. From that you can decide what the next gadget to receive focus should be.

The TAB key generates an event of $9000 along with 'event data' being +1
The SHIFT+TAB key generates an event of $9000 along with 'event data' being -1

; Textboxes - adding 2 values
; with TABBING support and textbox 'character selection'

; userlibs
; ************************
; .lib "user32.dll"
; SendMessage%(hwnd,msg,wParam,mParam):"SendMessageA"
; GetFocus%():"GetFocus"
; ************************

Const EM_SETSEL=$b1 ;  select a range of characters in an edit control

Dim gad(4)
Gosub CreateGUI

Repeat
 ev=WaitEvent()
 DebugLog "Event = $"+Right$(Hex$(ev),4) + "   "+EventSource() + "   "+EventData()
 Select ev
  Case $803 ; close [X]
  Exit
  Case $401 ;gadgethit
  total#=Float(TextFieldText(gad(1)))+Float(TextFieldText(gad(2)))
  SetGadgetText gad(3),Str$(total)
  lastgad=EventSource()
  Case $9000 ; TAB key event
  If GetFocus()=QueryObject(gad(1),1) Then gd=gad(2) Else gd=gad(1)
  ActivateGadget gd
  SendMessage QueryObject(gd,1),EM_SETSEL,0,-1 ; select 'all' characters
 End Select
Forever

End

.CreateGUI
 win = CreateWindow("Adder",176,193,284,123,Desktop(),1)
 gad(1) = CreateTextField(20,20,100,20,win,0)
 gad(2) = CreateTextField(150,20,100,20,win,0)
 gad(3) = CreateTextField(106,56,100,20,win,0)
 CreateLabel("+",133,21,9,15,win,0)
 CreateLabel("=",80,57,10,16,win,0)
 HotKeyEvent 15,0,$9000,+1              ; TAB forward
 HotKeyEvent 15,1,$9000,-1              ; TAB back (Shift+TabKey)
 HotKeyEvent 1,0,$803                   ; ESC
 ActivateGadget gad(1)
Return



soja(Posted 2004) [#5]
@SyntaxError: However, have you found a way to stop it from beeping?

Also, people may want to check out my example. I set it up to support easy additions of and rearrangements of gadgets in the tab order list. Here:
B+: Use TAB to switch between text fields..?

For example, if you want to add a gadget to the tab cycle, just add a CreateTabCycleGadget line in the InitTabCycle function. To rearrange the order, just rearrange the lines of code.


Eikon(Posted 2004) [#6]
@Sin: I posted something much simpler that requires no api in your BC.com post.


EOF(Posted 2004) [#7]
@SyntaxError: However, have you found a way to stop it from beeping?
No. Not yet. It appears the TAB key is classed as illegal whilst in a text field.
I wonder whether there is a SendMessage call available to disable the message beep(?)


soja(Posted 2004) [#8]
I wonder whether there is a SendMessage call available to disable the message beep(?)

Yeah. I doubt it, though. It's probably processing the WM_CHAR event (as a result of you pressing TAB) and then calling MessageBeep.

WM_CHAR

Writes a character to the single-line edit control and sends the EN_UPDATE and EN_CHANGE notification messages to the parent window. Writes a character to the multiline edit control. Handles the accelerator keys for standard functions, such as CTRL+C for copying and CTRL+V for pasting. In multiline edit controls, also processes TAB, and CTRL+TAB keystrokes to move among the controls in a dialog box and to insert tabs into multiline edit controls. Uses the MessageBeep function for illegal characters.


I don't think you could intercept this, because the hotkey event invariably occurs after the Blitz engine/Windows processes the WM_CHAR event. It would have to be changed (if possible) when the gui is made available to the user, which would probably have some unwanted side effects.

My fingers are still crossed, though.


Hansie(Posted 2004) [#9]
@all

I don't get it. BlitzPlus's strength compared to Blitz3D should be its ability to simulate Windows applications, and to develop Windows applications. Using "TAB" between fields is common to everyone, and to me its a big mystery why BlitzPlus does not support this *without* calls to api

I guess its another item to add to a future patch for BlitzPlus


CS_TBL(Posted 2004) [#10]
Maybe you can keep up a list of gadgeds in an array or bank, and when you press tab then you jump to the next gadget in the array and activate it.. didn't try it tho, but it's the only thing I can come up with .. :)


Eikon(Posted 2004) [#11]
.


Sin of Nature(Posted 2004) [#12]
Wow! Not been here for a few days and there's been quite a debate going on. Thanks for the help all.

Sin


Snarty(Posted 2004) [#13]
*cough* this should be sorted by now *cough*


Mr Brine(Posted 2004) [#14]
Check this out:

http://www.blitzbasic.com/codearcs/codearcs.php?code=935

Mr Brine