January 20, 2021, 01:19:18 PM

Author Topic: [bb] GadGetKey_TextArea by ShadowTurtle [ 1+ years ago ]  (Read 567 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] GadGetKey_TextArea by ShadowTurtle [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : GadGetKey_TextArea
Author : ShadowTurtle
Posted : 1+ years ago

Description : Hi.

Here is a small sample:

...
While Programm
  ...
  A$ = GadGetKey_TextArea(MyTextArea)
  If A$ = "j" Then RuntimeError "You pressed 'j' in TextArea"
Wend


Code :
Code: BlitzBasic
  1. wnd = CreateWindow("GadGet Key - Test", 10, 10, 400, 400, 0, 1)
  2. butn1 = CreateButton("Exit.", 2, 2, 100, 30, wnd)
  3. textlabel = CreateLabel("Please press a key in textarea.", 120, 2, 200, 20, wnd)
  4.  
  5. textarea = CreateTextArea(2, 40, 388, 300, wnd)
  6.  
  7. Programm = 1
  8. While Programm
  9.   MyEvent = WaitEvent()
  10.   If EventSource() = butn1 Then Programm = 0
  11.  
  12.   If EventSource() = textarea Then
  13.     I$ = GadGetKey_TextArea$(textarea)
  14.     SetGadgetText textlabel, "You have lost pressed: " + I$
  15.   End If
  16. Wend
  17.  
  18.  
  19. Type ScanGadGetKey
  20.   Field GadGetHandle
  21.   Field LostGadGetText$
  22.   Field NewGadGetText$
  23.   Field GadGetType
  24. End Type
  25.  
  26. Function GadGetKey_TextArea$(objhandle)
  27.   Local SGGK.ScanGadGetKey
  28.   SGGK = Null
  29.   For ScanGadGetKey.ScanGadGetKey = Each ScanGadGetKey
  30.     If ScanGadGetKeyGadGetHandle = objhandle Then SGGK = ScanGadGetKey
  31.   Next
  32.  
  33.   If SGGK = Null Then
  34.     SGGK.ScanGadGetKey = New ScanGadGetKey
  35.     SGGKGadGetHandle = objhandle
  36.     SGGKLostGadGetText$ = TextAreaText$(objhandle)
  37.     SGGKGadGetType = 0
  38.     Return GadGetKey_TextArea$(objhandle)
  39.   Else
  40.     SGGKLostGadGetText$ = SGGKNewGadGetText$
  41.     SGGKNewGadGetText$ = TextAreaText$(SGGKGadGetHandle)
  42.     For GGKT = 1 To Len(SGGKNewGadGetText$)
  43.       If Not (Mid$(SGGKNewGadGetText$, GGKT, 1) = Mid$(SGGKLostGadGetText$, GGKT, 1)) Then
  44.         Return Mid$(SGGKNewGadGetText$, GGKT, 1)
  45.       End If
  46.     Next
  47.   End If
  48. End Function


Comments :


danielos(Posted 1+ years ago)

 could you do this also for mouseclicks and keys like [CTRL] and [Enter] ?


ShadowTurtle(Posted 1+ years ago)

 This isnt possible without winapi, i think. The solution on top uses only blitzplus commands. No winapi-userlib is required.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal