Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


how to write listbox's item by Text or clipoard?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
cancandodo
Advanced Cheater
Reputation: 0

Joined: 09 Mar 2012
Posts: 70

PostPosted: Mon Feb 13, 2023 8:41 am    Post subject: how to write listbox's item by Text or clipoard? Reply with quote

for ex:
my clipoard's text is

"aa
bb
cc
dd
ee
"


===================
if i use "listbox1.item[0]=readFromClipboard()"

result is

listbox1.item[0]=aabbccddee



i want to paste this text to listbox1

resul↓↓↓↓↓

listbox1.item[0]=aa
listbox1.item[1]=bb
listbox1.item[2]=cc
listbox1.item[3]=dd
listbox1.item[4]=ee
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Mon Feb 13, 2023 9:44 am    Post subject: Reply with quote

This will split the text in the clipboard by space and then add each word to the listbox.
Code:

if f then f.destroy(); f = nil end

f = createForm(getMainForm())
f.Name = 'frmLB'
f.Caption = 'List'
f.Width = 200
f.Height = 250
f.CenterScreen()

l = createListBox(f)
l.Width = f.Width
l.Height = f.Height

function addWordsToList(listbox)
  local c = readFromClipboard()
  if c == nil then return end
  -- Split copied text by space and add each word
  -- To the listbox
  for w in c:gmatch('([^%s]+)') do
    listbox.Items.Add(w)
  end
end

addWordsToList(l)
Back to top
View user's profile Send private message
cancandodo
Advanced Cheater
Reputation: 0

Joined: 09 Mar 2012
Posts: 70

PostPosted: Mon Feb 13, 2023 10:04 am    Post subject: Reply with quote

LeFiXER wrote:
This will split the text in the clipboard by space and then add each word to the listbox.
Code:

if f then f.destroy(); f = nil end

f = createForm(getMainForm())
f.Name = 'frmLB'
f.Caption = 'List'
f.Width = 200
f.Height = 250
f.CenterScreen()

l = createListBox(f)
l.Width = f.Width
l.Height = f.Height

function addWordsToList(listbox)
  local c = readFromClipboard()
  if c == nil then return end
  -- Split copied text by space and add each word
  -- To the listbox
  for w in c:gmatch('([^%s]+)') do
    listbox.Items.Add(w)
  end
end

addWordsToList(l)


this code has a problem
if text inclued blank ,it will be output "enter"

for ex


aa bb
cc dd

i want to

listbox1.item[0]=aa bb
listbox1.item[1]=cc dd

but use this code,the result is

listbox1.item[0]=aa
listbox1.item[1]=bb
listbox1.item[2]=cc
listbox1.item[3]=dd
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Mon Feb 13, 2023 10:30 am    Post subject: Re: how to write listbox's item by Text or clipoard? Reply with quote

cancandodo wrote:
for ex:
...
i want to paste this text to listbox1

resul↓↓↓↓↓

listbox1.item[0]=aa
listbox1.item[1]=bb
listbox1.item[2]=cc
listbox1.item[3]=dd
listbox1.item[4]=ee


I did as you requested, albeit not totally error free.

Code:

if f then f.destroy(); f = nil end

f = createForm(getMainForm())
f.Name = 'frmLB'
f.Caption = 'List'
f.Width = 200
f.Height = 250
f.CenterScreen()

l = createListBox(f)
l.Width = f.Width
l.Height = f.Height

function addWordsToList(listbox)
  local c = 'aa bb cc dd ee'--readFromClipboard()
  if c == nil then return end
  -- Split copied text by space and add each word
  -- To the listbox
  local i = 0
  local s = ''
  for w in c:gmatch('([^%s]+)') do
    if w then
       s = s:sub(2,#s) .. ' ' .. w
       i = i + 1
    end

    if i == 2 and s ~= nil then
      listbox.Items.Add(s)
      s = ''
      i = 0
    end
  end
end

addWordsToList(l)


Definitely not the best way to do this, but it works. If the text is blank then the form will be blank naturally.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1533

PostPosted: Tue Feb 14, 2023 8:20 am    Post subject: Reply with quote

Simple gluing procedure:
Code:
ClipboardText = [[dd
bb
aa
cc
ee]]

writeToClipboard(ClipboardText)

if UDF1 then UDF1.Destroy() end
  UDF1 = createForm()

  list1 = createListBox(UDF1)

function TableView(text)
 exTbl = {}
 sl = createStringList()
 sl.Text = text
  for i=0, sl.Count -1 do
   exTbl[i+1] = sl[i]
  end
  --sort table a.. z
  table.sort(exTbl)
 return exTbl
end

list1.OnClick=function()
aa =  TableView(readFromClipboard())
  for i,k in pairs(aa) do
   list1.items[i-1] = k
  end
end


List selection, testing and shortcut option:
Code:
ClipboardText = [[dd
bb
aa
cc
ee]]

writeToClipboard(ClipboardText)

if UDF1 then UDF1.Destroy() end
  UDF1 = createForm()

  list1 = createListBox(UDF1)
  list1.Name = "list1"
  list1.MultiSelect = true
  list2 = createListBox(UDF1)
  list2.Top = list1.Height + 10
  list2.Name = "list2"

local listEx = ""

function TableView(text)
 exTbl = {}
 sl = createStringList()
 sl.Text = text
  for i=0, sl.Count -1 do
   exTbl[i+1] = sl[i]
  end
  --sort table a.. z
  table.sort(exTbl)
 return exTbl
end

list1.OnMouseDown=function() listEx = list1 end
list2.OnMouseEnter=function() listEx = list2 end

function pasteList()
 sleep(200)
 if listEx=="" then
  showMessage("Please click on a list and choose!")
 else
  answer = messageDialog("Selected list: "..listEx.Name.. ". Do you confirm?", mtWarning, mbYes, mbNo)
   if answer == mrYes then
    aa =  TableView(readFromClipboard())
     for i,k in pairs(aa) do
      listEx.items[i-1] = k --Clear list and update
     end
     listEx = ""
   end
  end
end

if pasteKey1 then pasteKey1.Destroy() pasteKey1=nil end

pasteKey1 = createHotkey(pasteList, VK_CONTROL,VK_V)



You can choose the suitable one.
If you find it necessary, I can add an option to update (replace) the selected text.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites