News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Pages (2): « First [1] 2 Next > Last »
How to bind a key event for widget?
Author Message
jyf1987
Member
***


Posts: 58
Group: Registered
Joined: Jun 2008
Status: Offline
Reputation: 0
Post: #1
How to bind a key event for widget?

i want to bind a key event function for a input widget
to check if user has press the enter key
so how to do that??


Cheers
jyf
09-13-2008 11:45 PM
Find all posts by this user Quote this message in a reply
MrBill
Junior Member
**


Posts: 14
Group: Registered
Joined: Mar 2008
Status: Offline
Reputation: 0
Post: #2
RE: How to bind a key event for widget?

Code:
do widget= fltk:Fl_Input(0,0,0,0,"")
widget:callback(input_cb)
widget:when(8) -- this is the constant for the Enter key


Don't use that code exactly as its missing dimensions and labels
But the widget:when(8) is what you are looking for.

There is a list of constants for events and I always forget where they are, either somewhere in the forums, in murgaLua examples, or maybe in Mikshaws widget example.

I use Fluid and then convert to lua so thats how I get it done, usually.

09-14-2008 07:03 AM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #3
RE: How to bind a key event for widget?

MrBill Wrote:
I use Fluid and then convert to lua so thats how I get it done, usually.


You just beat me to it :-)

The verbose version would be :

Code:
widget:when(fltk.FL_WHEN_ENTER_KEY_ALWAYS)

09-14-2008 07:22 AM
Visit this user's website Find all posts by this user Quote this message in a reply
jyf1987
Member
***


Posts: 58
Group: Registered
Joined: Jun 2008
Status: Offline
Reputation: 0
Post: #4
RE: How to bind a key event for widget?

thank you very much
when i dont get the answer i use set_event_handler to solver the problem
the code is

Code:
function quit_callback(msg)
   if fltk.fl_choice("Are you sure you want to EXIT ?", "No", "Yes", nil) >= 1 then
      w:hide()
      os.exit()
   end
end

function all_event(event)
  if(Fl:event_key(FL_Enter) and murgaLua.getFltkEventText(event)=="FL_SHORTCUT") then
    msgout:add(msgin:value())
    msgout:bottomline(msgout:size())
    msgin:value("")
  end
end

ww,wh,wt=300,280,"Simple IRC Client - Powered by jyf1987"

w= fltk:Fl_Window(ww,wh,wt)
w:callback(quit_callback)

msgout= fltk:Fl_Browser(5, 5, 290, 240)

msgin= fltk:Fl_Input(5, 250, 290, 25)





w:show()

Fl.set_event_handler(all_event)
Fl:start_event_handler()
Fl:run()


also it's easy to use widget:when(fltk.FL_WHEN_ENTER_KEY_ALWAYS)

here is the new code

Code:
function quit_callback(msg)
   if fltk.fl_choice("Are you sure you want to EXIT ?", "No", "Yes", nil) >= 1 then
      w:hide()
      os.exit()
   end
end

ww,wh,wt=300,280,"Simple IRC Client - Powered by jyf1987"

w= fltk:Fl_Window(ww,wh,wt)
w:callback(quit_callback)

msgout= fltk:Fl_Browser(5, 5, 290, 240)


msgin= fltk:Fl_Input(5, 250, 290, 25)
msgin:callback(
function()
  msgout:add(msgin:value())
  msgout:bottomline(msgout:size())
  msgin:value("")
end
)
msgin:when(fltk.FL_WHEN_ENTER_KEY_ALWAYS)


w:show()

Fl:run()


Cheers
jyf
09-14-2008 12:55 PM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #5
RE: How to bind a key event for widget?

jyf1987 Wrote:
thank you very much
when i dont get the answer i use set_event_handler to solver the problem

Great examples, thanks :-)

The only problem with using the event handler is that input fields will absorb the enter key (as a tab to next field) unless you mess around with when (say a when(0)).

Another tip is to use event_inside(widget), as this allows you (when using the event_handler) to know what widget you where in when the event occured.

Cheers
JohnM

09-15-2008 12:13 AM
Visit this user's website Find all posts by this user Quote this message in a reply
jyf1987
Member
***


Posts: 58
Group: Registered
Joined: Jun 2008
Status: Offline
Reputation: 0
Post: #6
RE: How to bind a key event for widget?

thx for the tip
so anyother secret? Big Grin


Cheers
jyf
09-15-2008 10:37 PM
Find all posts by this user Quote this message in a reply
jyf1987
Member
***


Posts: 58
Group: Registered
Joined: Jun 2008
Status: Offline
Reputation: 0
Post: #7
RE: How to bind a key event for widget?

i'am looking forward fltk2 to be support
for displaying chinese chars,any way,even that wont be support the murgalua is still a powerful tool for me,good works


Cheers
jyf
09-15-2008 10:42 PM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #8
RE: How to bind a key event for widget?

jyf1987 Wrote:
thx for the tip
so anyother secret? Big Grin


Lots ... That's why I have to write some updated docs :-)

Cheers
JohnM

09-15-2008 11:37 PM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #9
RE: How to bind a key event for widget?

Although I'm not sure how well this would work for your needs, if at all, you could try using decimal codes to display the Chinese characters. It isn't ideal, of course, since it will not translate to other machines that don't have the exact font, and without some special magic it is probably useful only for static strings.

Here is a script that will display 256 characters available in the FL_SCREEN font. You'll need to add a set_font line to get your desired font:
Fl:set_font(fltk.FL_SCREEN,"my_font_name")
Optionally change bro:textfont() to a different constant.

EDIT: Then again, maybe just changing the font would provide the same level of usefulness/uselessness

Code:
odd=nil
ww=500; wh=350
win=fltk:Fl_Window(ww,wh,"decimal codes")
bro=fltk:Fl_Browser(10,10,ww/2-20,wh-20)
bro:textfont(fltk.FL_SCREEN)
for i=0,255 do
if i<10 then t="  " elseif i<100 then t=" " else t="" end
if odd then odd=nil; col="@B52@." else odd=1; col="" end
bro:add(col..t..i.."\t"..string.format('%c',i))
end
box=fltk:Fl_Multiline_Output(ww/2,10,ww/2-10,wh-20)
box:textsize(12)
box:set_output()
box:value([[
When including an escaped string of
1, 2, or 3 decimals as part of a Lua
string, those decimals will be read
as the character matching that code.
For example, \64 shows '@' and \10 is
a newline character on systems that
use ASCII:97

In this particular demo, the lines in
the browser were added programatically
rather than being provided as a full
string. Concatenating an escape character
to the string it is intended to escape
is seemingly impossible, but you can get
the same result with string.format:
string.format('%c',number)

Results may vary depending on your
system's configuration or chosen font.
]])
win:show()
Fl:run()

This post was last modified: 09-15-2008 11:44 PM by mikshaw.

09-15-2008 11:39 PM
Find all posts by this user Quote this message in a reply
jyf1987
Member
***


Posts: 58
Group: Registered
Joined: Jun 2008
Status: Offline
Reputation: 0
Post: #10
RE: How to bind a key event for widget?

it is cool ,but chinese char use 2 bytes so 256 will not enough


Cheers
jyf
09-16-2008 12:21 AM
Find all posts by this user Quote this message in a reply
Pages (2): « First [1] 2 Next > Last »
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: