| Reply | « Previous Thread | Next Thread » |
|
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? |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
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. |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
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. |
|
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() 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? |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
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.
|
|
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() |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
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() |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
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. |
|
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 ![]() |
|
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() 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() wtf, am i too dumb to get this simple thing to work?! ![]() whats wrong? |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
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.
|
|
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 |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Rafael T.
Offline
Forum Nokia Champion
|
|
|
Quote:
![]() 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 ![]() 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. |
|
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() 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) |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
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 | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| 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 |