You Are Here:

Community: Developer Discussion Boards

Reply « Previous Thread | Next Thread »

#1 Old Need Help!! shortcuts to flashmodes - run in background - 2008-10-29, 20:27

Join Date: Jun 2008
Posts: 34
kwik
Offline
Registered User
I try to create a little app to run in background while using the default camera app and allow to switch through flash modes by pressing a button on numpad. Is this generally possible?

in example you have to press 4 to set flash forced:
...
def set_flashforce():
global flash
flash = 'forced'
appuifw.note(u"Flash Forced")

pic = camera.take_photo(resolution, flash)

canvas.bind(key_codes.EKey4, set_flashforce)
...

When i run app and press 4 i get message "Flash Forced", but when i take picture flash is not activated? Whats wrong here?


If its not possible to access camera module while already using the camera i would like to do something like this:

by pressing 4 a function (one) is started which presses a row of keys needed to deactivate flash (numpad left, select, numpad right, select)
...
def one():
EKeyleftarrow
EKeyselect
EKeyrightarrow
EKeyselect
appuifw.note(u"flash forced")

def two():
appuifw.note(u"working")

canvas.bind(key_codes.EKey2, one)
canvas.bind(key_codes.EKeyselect, two)
...


to check if its working i defined a second function to write "workin" if select is pressed.

But this doesnt work either. Whats wrong here?

Which of the two ideas might work? and how do i get the programm to run in background?
Reply With Quote

#2 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-29, 20:41

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
I'm sorry but I don't quite understand. Do you want to set the flash mode of the default camera application through Python? That isn't possible. Not directly, anyway.

The only solution I see is what you described, simulating key presses, but for this you would have to consider that the camera settings aren't opened instantaneously (meaning that it takes a while to load the settings screen), so some key presses will probably be wasted (that's probably why you got "working" but it didn't really work).

As for switching your app from background to foreground and vice-versa, try appswitch.
Reply With Quote

#3 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-29, 20:50

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Hi kwik,

Bogdan is right, your questions are quite confusing

You should use code tag to post your codes, so it keeps identation and will be more clear for us to read.

As Bogdan said, you can't select the camera's default application flash.

For using camera module, you should do a camera interface in your own application, and then you can set the flash for your application, but not for the default one.

You could simulate the keys but you will have to use a timer for waiting a little bit between the simulations, since the camera's default application does not respond immediately to the keypresses, as my friend Bogdan also told you.

If you want to see how to implement the camera in your own application, you can see this article.


Hope it helps,

Rafael.
Reply With Quote

#4 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-29, 22:01

Join Date: Jun 2008
Posts: 34
kwik
Offline
Registered User
Ok, let me try to describe this a little more,

i have a n82, when i open the coverage camera application is starting. Now i want that if i press "4" the flash is activated, instead of pressing through menu.

screen looks like this

as you can see the settings are always opened, so i should not need a timer.

Code:
import appuifw, e32, key_codes

def one():
  EKeyleftarrow
  EKeyselect
  EKeyrightarrow
  EKeyselect
  appuifw.note(u"flash forced")

def two():
  appuifw.note(u"working")

canvas = appuifw.Canvas()
appuifw.app.body = canvas

canvas.bind(key_codes.EKey2, one)
canvas.bind(key_codes.EKeyselect, two)

appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
app_lock.wait()
The function "one" should simulate the keypresses: EKeyleftarrow, then EKeyselect, then EKeyrightarrow, then EKeyselect and then give out message: Flash forced

Cause i didnt know if the keypresses were simulated or not, i added the function "two". So when keypress EKeyselect is simulated i should get the message "working".

But that doesnt happen, if i press "4" i just get the message "flash forced". So i think that the keypresser are not simulated.
I didnt run app in background, i just tested it by itself.

So is the code generally ok, or do i need to change something?

I had a look appswitch, but dont know how to handle it yet. With this module i can set app to be running in background, still detecting when i press the "4"? Right?
Reply With Quote

#5 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-29, 22:09

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
I assume you're using keypress to simulate keypresses and not just writing EKeyselect and others like that, right? As for detecting keypresses while the app is in background, yes, it's possible.
Reply With Quote

#6 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-29, 22:19

Join Date: Jun 2008
Posts: 34
kwik
Offline
Registered User
No i didnt!

so it have to look like this?

Code:
import appuifw, e32, key_codes

def one():
  simulate_key(EKeyleftarrow)
  simulate_key(EKeyselect)
  simulate_key(EKeyrightarrow)
  simulate_key(EKeyselect)
  appuifw.note(u"flash forced")

def two():
  appuifw.note(u"working")

canvas = appuifw.Canvas()
appuifw.app.body = canvas

canvas.bind(key_codes.EKey2, one)
canvas.bind(key_codes.EKeyselect, two)

appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
app_lock.wait()
Reply With Quote

#7 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-29, 22:25

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Something like this:
Code:
import appuifw, e32, keypress
from key_codes import *

def one():
  keypress.simulate_key(EKeyLeftArrow, EScancodeLeftArrow)
  keypress.simulate_key(EKeySelect, EScancodeSelect)
  keypress.simulate_key(EKeyRightArrow, EScancodeRightArrow)
  keypress.simulate_key(EKeySelect, EScancodeSelect)
  appuifw.note(u"flash forced")

def two():
  appuifw.note(u"working")

canvas = appuifw.Canvas()
appuifw.app.body = canvas

canvas.bind(key_codes.EKey2, one)
canvas.bind(key_codes.EKeyselect, two)

appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
app_lock.wait()
Reply With Quote

#8 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-29, 22:29

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Yes, you should use Bogdan's example. But I would also use a little timer between key simulations, since the camera's application does not respond to them instantaneously, as we both told you on the previous posts.


BR,

Rafael.
Reply With Quote

#9 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-29, 22:45

Join Date: Jun 2008
Posts: 34
kwik
Offline
Registered User
Ok, when i get this working, i'll check how to write the code to add a timer between keypresses.
after that how to put app in background.

im very new to this, i dont know how to formulate the codepieces correctly. so this will take some time
Reply With Quote

#10 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-29, 23:48

Join Date: Jun 2008
Posts: 34
kwik
Offline
Registered User
tried some combinations:

when i try:
Code:
import appuifw, e32, keypress
from key_codes import * 

def one():
  keypress.simulate_key(EKey1, EScancode1)
  keypress.simulate_key(EKey3, EScancode3)
  appuifw.note(u"flash forced")

def two():
  appuifw.note(u"working")

def quit():
  app_lock.signal()

canvas = appuifw.Canvas()
appuifw.app.body = canvas

canvas.bind(key_codes.EKey2, one)
canvas.bind(key_codes.EKey1, two)

appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
app_lock.wait()
app is not starting, error message: name 'key_codes' is not defined

when i try:

Code:
import appuifw, e32, keypress, key_codes 

def one():
  keypress.simulate_key(EKey1, EScancode1)
  keypress.simulate_key(EKey3, EScancode3)
  appuifw.note(u"flash forced")

def two():
  appuifw.note(u"working")

def quit():
  app_lock.signal()

canvas = appuifw.Canvas()
appuifw.app.body = canvas

canvas.bind(key_codes.EKey2, one)
canvas.bind(key_codes.EKey1, two)

appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
app_lock.wait()
app is starting, but nothing happens when key pressed? error message: global name 'EKey1' not defined.

wtf, am i too dumb to get this simple thing to work?!
whats wrong?
Reply With Quote

#11 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-30, 00:08

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Hi kwik,

Just relax man, you are doing it right. Your problem is only with importing the key_codes module.

First script:

When you use from key_codes import *, you can't call key_codes, since you are importing all the content from the module, so you can apply it directly. In this case, the correct thing is to use just EKey1, so you can take the keypress.EKey1 from canvas.bind() and just let EKey1.


Second script:

Exactly the opposite of the first one. If you use import key_codes you must call keypress. So you should use keypress.simulate_key(key_codes.EKey1, key_codes.EScancode1).


Finally, the easier code would be this:

Code:
import appuifw, e32, keypress
from key_codes import * 

def one():
  keypress.simulate_key(EKey1, EScancode1)
  keypress.simulate_key(EKey3, EScancode3)
  appuifw.note(u"flash forced")

def two():
  appuifw.note(u"working")

def quit():
  app_lock.signal()

canvas = appuifw.Canvas()
appuifw.app.body = canvas

canvas.bind(EKey2, one)
canvas.bind(EKey1, two)

appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
app_lock.wait()

Hope it helps,

Rafael.
Last edited by Rafael T. : 2008-10-30 at 00:18.
Reply With Quote

#12 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-30, 00:28

Join Date: Jun 2008
Posts: 34
kwik
Offline
Registered User
Wicked!
now i understand why i got these errors.

Thanks Rafael!

now i have to study some examples on how to put timers between keypress commands and put app in background, that will take some time.

till then
Greets to brazil
Reply With Quote

#13 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-30, 00:36

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Quote:
Originally Posted by kwik View Post
Wicked!
now i understand why i got these errors.

Thanks Rafael!

now i have to study some examples on how to put timers between keypress commands and put app in background, that will take some time.

till then
Greets to brazil
Hi again

Actually it won't take almost any time to implement a timer.

See the example:

Code:
import e32

e32.ao_sleep(2) # 2 indicates time in seconds
Quite easy, huh?

This should make the application wait 2 seconds, and then call the function written in next line (in your code, it should be a keypress simulation).


Cheers for your country too!



BR,

Rafael.
Reply With Quote

#14 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-30, 22:50

Join Date: Jun 2008
Posts: 34
kwik
Offline
Registered User
I managed to add a delay between my keysimulations with a counter function. Today i read your post, and its much easier your way

i changed the simulated keypresses with some notes to see if timer working.

Code:
import appuifw, e32, keypress 
import appswitch   
from key_codes import * 

def one():
  appuifw.note(u"one") 
  e32.ao_sleep(10) 
  appuifw.note(u"two")  

 
def quit():
  app_lock.signal()

canvas = appuifw.Canvas()
appuifw.app.body = canvas

canvas.bind(EKey2, one)

appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
app_lock.wait()
Timer working great!
But when i switch programm to background manually, and press "2" nothing happens. Seems like keypress is not detected?

i read of a module called keycapture, do i need this to recognize keypress, or whats wrong?

btw i tried to use
Code:
appswitch.application_list(0)
command to see if "camera" is running. the keysimulation should only be executed when "camera" is active. but there is no list of running apps?
Reply With Quote

#15 Old Re: Need Help!! shortcuts to flashmodes - run in background - 2008-10-30, 23:17

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Hi kwik,

Great to know the timer worked

About capturing keypresses in background, you should use keycapture module, as you mentioned.

You can try this code:

Code:
import e32, keycapture

def key_cap(a_key):
    if a_key==keycapture.EKey2:
        # Do something ...

    elif a_key==keycapture.EKey3:
        # Do something ...


def quit():
    app_lock.signal()
    capturer.stop()

capturer=keycapture.KeyCapturer(key_cap)
capturer.keys=(keycapture.EKey2,keycapture.EKey3)
capturer.start()

app_lock = e32.Ao_lock()
app_lock.wait()

Hope it helps,

Rafael
Last edited by Rafael T. : 2008-10-30 at 23:36.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Application not runing in background sriramadasu General Symbian C++ 7 2008-10-06 11:55
How to make a program run in background xhsoldier General Symbian C++ 7 2008-08-28 08:44
Run a symbian exe file in background arunshah General Symbian C++ 6 2006-12-26 12:28
Run a symbian exe file in background arunshah General Symbian C++ 2 2006-12-04 16:58
Set the app to run in background from code symsym Symbian User Interface 3 2005-10-29 18:40

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia