Simulating keyboard events

Hello,

from browsing the archives, it seems that simulating events is tricky and can't be done from wxpython. I can live with that for mouse events, which are tricky to get right in any case, but keyboard events would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard event to the application, so that all the codepaths (including focus etc) are exercised during a test run? Or native events *have* to be synthesised? I am using the STC widget along some other simple text ctrls.

Thanks,
Orestis

···

--
orestis@orestis.gr
http://orestis.gr/

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

keymodule.c (1.5 KB)

setup.py (412 Bytes)

···

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

http://trac.wxwidgets.org/browser/sandbox/trunk/UIEventSim/

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

···

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Kevin,

that looks exactly what I need. I have a Mac so it fits my needs 100%. Is this accessible in any of the release builds of wxPython or do I have to build my own from source?

I will also have to test from Windows but it shouldn't be too hard to implement a similar interface (with some help, I don't have a clue about how wx is implemented), since the Win32 API has methods to create events like that.

Thanks,
Orestis

···

--
orestis@orestis.gr

On 18 Jan 2009, at 18:33, Kevin Ollivier wrote:

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

wxTrac has been migrated to GitHub Issues - wxWidgets

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Orestis Markou wrote:

Is there any reasonable way of synthesising and sending a keyboard event to the application, so that all the codepaths (including focus etc) are exercised during a test run? Or native events *have* to be synthesised? I am using the STC widget along some other simple text ctrls.

On Windows you could use this:
   http://www.autohotkey.com/

Michael

Hi Orestis,

Hi Kevin,

that looks exactly what I need. I have a Mac so it fits my needs 100%. Is this accessible in any of the release builds of wxPython or do I have to build my own from source?

You have to build from source for now. Once it's complete (i.e. also implemented on Win/Linux), I'm planning on moving it into the wx / wxPython build process so that it will be directly accessible via wxPython.

I will also have to test from Windows but it shouldn't be too hard to implement a similar interface (with some help, I don't have a clue about how wx is implemented), since the Win32 API has methods to create events like that.

mouse_event and keybd_event should allow us to implement these APIs. It shouldn't require too much knowledge about how wx is implemented, though, as you're mostly simulating native key and mouse events. There will probably be special work needed to handle non-ASCII characters, but I think even starting with ASCII support would be a huge plus. :slight_smile:

Thanks,

Kevin

···

On Jan 18, 2009, at 11:48 AM, Orestis Markou wrote:

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 18:33, Kevin Ollivier wrote:

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

wxTrac has been migrated to GitHub Issues - wxWidgets

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

I'll try building my own wxpython/wxwidgets. It seems like it's documented enough, hopefully I'll have no problems. How is UIEventSim built?

···

--
orestis@orestis.gr

On 18 Jan 2009, at 22:05, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 11:48 AM, Orestis Markou wrote:

Hi Kevin,

that looks exactly what I need. I have a Mac so it fits my needs 100%. Is this accessible in any of the release builds of wxPython or do I have to build my own from source?

You have to build from source for now. Once it's complete (i.e. also implemented on Win/Linux), I'm planning on moving it into the wx / wxPython build process so that it will be directly accessible via wxPython.

I will also have to test from Windows but it shouldn't be too hard to implement a similar interface (with some help, I don't have a clue about how wx is implemented), since the Win32 API has methods to create events like that.

mouse_event and keybd_event should allow us to implement these APIs. It shouldn't require too much knowledge about how wx is implemented, though, as you're mostly simulating native key and mouse events. There will probably be special work needed to handle non-ASCII characters, but I think even starting with ASCII support would be a huge plus. :slight_smile:

Thanks,

Kevin

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 18:33, Kevin Ollivier wrote:

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

wxTrac has been migrated to GitHub Issues - wxWidgets

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Orestis,

I'll try building my own wxpython/wxwidgets. It seems like it's documented enough, hopefully I'll have no problems. How is UIEventSim built?

You actually shouldn't need to build your own wxWidgets/wxPython. As long as you have the wx-config for your wxPython on the PATH, it should build okay. Note that right now you also need Bakefile (I'd recommend getting 0.2.4 as 0.2.5 has an annoying assert that seems to be a false alarm) and the version of SWIG 1.3.29 Robin uses for wxPython, available from here: NameBright - Coming Soon

You will need to build SWIG, but it is pretty much a configure / make / make install deal. Note that both Bakefile and SWIG should be available on your PATH.

Let me know if you run into any snags!

Thanks,

Kevin

···

On Jan 18, 2009, at 2:50 PM, Orestis Markou wrote:

--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 22:05, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 11:48 AM, Orestis Markou wrote:

Hi Kevin,

that looks exactly what I need. I have a Mac so it fits my needs 100%. Is this accessible in any of the release builds of wxPython or do I have to build my own from source?

You have to build from source for now. Once it's complete (i.e. also implemented on Win/Linux), I'm planning on moving it into the wx / wxPython build process so that it will be directly accessible via wxPython.

I will also have to test from Windows but it shouldn't be too hard to implement a similar interface (with some help, I don't have a clue about how wx is implemented), since the Win32 API has methods to create events like that.

mouse_event and keybd_event should allow us to implement these APIs. It shouldn't require too much knowledge about how wx is implemented, though, as you're mostly simulating native key and mouse events. There will probably be special work needed to handle non-ASCII characters, but I think even starting with ASCII support would be a huge plus. :slight_smile:

Thanks,

Kevin

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 18:33, Kevin Ollivier wrote:

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

wxTrac has been migrated to GitHub Issues - wxWidgets

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

That worked perfectly. I actually used bakefile 0.2.3 (available from MacPorts). Swig built cleanly and so did UIEventSimulator. I noticed that SendText isn't actually implemented, although it failed because it expected a wxString (?). Also, for some reason, the keypress/keychar functions always send 'a'. You can see it by changing your test to send and expect 'd'.

Anyway, thanks a lot! Am I correct to assume that _eventsim.so, libeventsim.dylib and eventsim.py are the only outputs? I'd like to check them in to my repo so I don't have to build them every time.

It also occurred to me that for win32, the relevant functions are probably exposed through the pywin32 extensions. I'll have a look tomorrow and send you the relevant info.

Cheers,
Orestis

···

--
orestis@orestis.gr

On 18 Jan 2009, at 23:10, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 2:50 PM, Orestis Markou wrote:

I'll try building my own wxpython/wxwidgets. It seems like it's documented enough, hopefully I'll have no problems. How is UIEventSim built?

You actually shouldn't need to build your own wxWidgets/wxPython. As long as you have the wx-config for your wxPython on the PATH, it should build okay. Note that right now you also need Bakefile (I'd recommend getting 0.2.4 as 0.2.5 has an annoying assert that seems to be a false alarm) and the version of SWIG 1.3.29 Robin uses for wxPython, available from here: NameBright - Coming Soon

You will need to build SWIG, but it is pretty much a configure / make / make install deal. Note that both Bakefile and SWIG should be available on your PATH.

Let me know if you run into any snags!

Thanks,

Kevin

--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 22:05, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 11:48 AM, Orestis Markou wrote:

Hi Kevin,

that looks exactly what I need. I have a Mac so it fits my needs 100%. Is this accessible in any of the release builds of wxPython or do I have to build my own from source?

You have to build from source for now. Once it's complete (i.e. also implemented on Win/Linux), I'm planning on moving it into the wx / wxPython build process so that it will be directly accessible via wxPython.

I will also have to test from Windows but it shouldn't be too hard to implement a similar interface (with some help, I don't have a clue about how wx is implemented), since the Win32 API has methods to create events like that.

mouse_event and keybd_event should allow us to implement these APIs. It shouldn't require too much knowledge about how wx is implemented, though, as you're mostly simulating native key and mouse events. There will probably be special work needed to handle non-ASCII characters, but I think even starting with ASCII support would be a huge plus. :slight_smile:

Thanks,

Kevin

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 18:33, Kevin Ollivier wrote:

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

wxTrac has been migrated to GitHub Issues - wxWidgets

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Orestis,

That worked perfectly. I actually used bakefile 0.2.3 (available from MacPorts). Swig built cleanly and so did UIEventSimulator. I noticed that SendText isn't actually implemented, although it failed because it expected a wxString (?). Also, for some reason, the keypress/keychar functions always send 'a'. You can see it by changing your test to send and expect 'd'.

Looks like we need a way to map ASCII keys to 'virtual' key codes. What seems odd is that these codes are pretty much constant, but there isn't any mapping currently. There's an app that prints them, though, so I think I just need to alter it to spit them out to a sort of header file.

Anyway, thanks a lot! Am I correct to assume that _eventsim.so, libeventsim.dylib and eventsim.py are the only outputs? I'd like to check them in to my repo so I don't have to build them every time.

yes, that should be the case.

It also occurred to me that for win32, the relevant functions are probably exposed through the pywin32 extensions. I'll have a look tomorrow and send you the relevant info.

yes, it looks like they are. :slight_smile:

Thanks,

Kevin

···

On Jan 18, 2009, at 3:54 PM, Orestis Markou wrote:

Cheers,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 23:10, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 2:50 PM, Orestis Markou wrote:

I'll try building my own wxpython/wxwidgets. It seems like it's documented enough, hopefully I'll have no problems. How is UIEventSim built?

You actually shouldn't need to build your own wxWidgets/wxPython. As long as you have the wx-config for your wxPython on the PATH, it should build okay. Note that right now you also need Bakefile (I'd recommend getting 0.2.4 as 0.2.5 has an annoying assert that seems to be a false alarm) and the version of SWIG 1.3.29 Robin uses for wxPython, available from here: NameBright - Coming Soon

You will need to build SWIG, but it is pretty much a configure / make / make install deal. Note that both Bakefile and SWIG should be available on your PATH.

Let me know if you run into any snags!

Thanks,

Kevin

--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 22:05, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 11:48 AM, Orestis Markou wrote:

Hi Kevin,

that looks exactly what I need. I have a Mac so it fits my needs 100%. Is this accessible in any of the release builds of wxPython or do I have to build my own from source?

You have to build from source for now. Once it's complete (i.e. also implemented on Win/Linux), I'm planning on moving it into the wx / wxPython build process so that it will be directly accessible via wxPython.

I will also have to test from Windows but it shouldn't be too hard to implement a similar interface (with some help, I don't have a clue about how wx is implemented), since the Win32 API has methods to create events like that.

mouse_event and keybd_event should allow us to implement these APIs. It shouldn't require too much knowledge about how wx is implemented, though, as you're mostly simulating native key and mouse events. There will probably be special work needed to handle non-ASCII characters, but I think even starting with ASCII support would be a huge plus. :slight_smile:

Thanks,

Kevin

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 18:33, Kevin Ollivier wrote:

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

wxTrac has been migrated to GitHub Issues - wxWidgets

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

I just wrote that sample some years ago, and still use it as it is.
But of course it will be nice to have a platform independent way to
synthesize mouse and keyboard events; your idea is really nice.

···

On 1/18/09, Kevin Ollivier <kevin-lists@theolliviers.com> wrote:

Ivan, did you just write that code sample up or have you created a
similar Python binding for Linux?

Hi again - I'm having a read through the documentation of the Quartz events[1] - it seems that CGPostKeyboardEvent is obsolete, and CGEventCreateKeyboardEvent should be used instead. My patch follows.

From what I also gathered, converting from keycode/modifier to character depends on the keyboard layout. You can use UCKeyTranslate [2] to get the string from the keycode, but going the other way is more tricky. The Google Testing Toolkit has a translating function we could copy [3] (it's under the Apache 2.0 license).

There is also an interesting discussion at CocoaDev [4], which leads to a link to a .tgz file that has something that looks more robust (it's using the current keyboard layout and calls into some services, although my Objective-C-foo is non-existent so I may be talking nonsense). Unfortunately I've no idea how to progress from here.

Here's the patch:

Index: eventsim_mac.cpp

···

===================================================================
--- eventsim_mac.cpp (revision 58213)
+++ eventsim_mac.cpp (working copy)
@@ -47,6 +47,16 @@
      }
  }

+void SendCharCode(CGCharCode keycode, bool isDown)
+{
+ CGEventRef event = CGEventCreateKeyboardEvent(NULL, keycode, isDown);
+ if (event)
+ {
+ CGEventPost(kCGHIDEventTap, event);
+ }
+ CFRelease(event);
+}
+
  bool UIEventSimulator::MouseDown(int button)
  {
      CGPoint pos;
@@ -107,20 +117,21 @@
  bool UIEventSimulator::KeyPress(int keycode, bool isDown, bool shiftDown, bool cmdDown, bool altDown)
  {
      if (shiftDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)56, true);
+ SendCharCode((CGCharCode)56, true);
      if (altDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)58, true);
+ SendCharCode((CGCharCode)58, true);
      if (cmdDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)55, true);
+ SendCharCode((CGCharCode)55, true);

- CGPostKeyboardEvent((CGCharCode)keycode, 0, isDown);
-
+ SendCharCode((CGCharCode)keycode, isDown);
+
      if (shiftDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)56, false);
+ SendCharCode((CGCharCode)56, false);
      if (altDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)58, false);
+ SendCharCode((CGCharCode)58, false);
      if (cmdDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)55, false);
+ SendCharCode((CGCharCode)55, false);
+
      return true;
  }

[1]: http://developer.apple.com/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/func/CGEventCreateKeyboardEvent
[2]: http://developer.apple.com/documentation/Carbon/Reference/Unicode_Utilities_Ref/Reference/reference.html#//apple_ref/c/func/UCKeyTranslate
[3]: http://google-toolbox-for-mac.googlecode.com/svn/trunk/UnitTesting/GTMUnitTestingUtilities.m
[4]: http://www.cocoadev.com/index.pl?KeyCodesAndCharCodes
--
orestis@orestis.gr
http://orestis.gr/

On 19 Jan 2009, at 01:03, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 3:54 PM, Orestis Markou wrote:

That worked perfectly. I actually used bakefile 0.2.3 (available from MacPorts). Swig built cleanly and so did UIEventSimulator. I noticed that SendText isn't actually implemented, although it failed because it expected a wxString (?). Also, for some reason, the keypress/keychar functions always send 'a'. You can see it by changing your test to send and expect 'd'.

Looks like we need a way to map ASCII keys to 'virtual' key codes. What seems odd is that these codes are pretty much constant, but there isn't any mapping currently. There's an app that prints them, though, so I think I just need to alter it to spit them out to a sort of header file.

Anyway, thanks a lot! Am I correct to assume that _eventsim.so, libeventsim.dylib and eventsim.py are the only outputs? I'd like to check them in to my repo so I don't have to build them every time.

yes, that should be the case.

It also occurred to me that for win32, the relevant functions are probably exposed through the pywin32 extensions. I'll have a look tomorrow and send you the relevant info.

yes, it looks like they are. :slight_smile:

Thanks,

Kevin

Cheers,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 23:10, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 2:50 PM, Orestis Markou wrote:

I'll try building my own wxpython/wxwidgets. It seems like it's documented enough, hopefully I'll have no problems. How is UIEventSim built?

You actually shouldn't need to build your own wxWidgets/wxPython. As long as you have the wx-config for your wxPython on the PATH, it should build okay. Note that right now you also need Bakefile (I'd recommend getting 0.2.4 as 0.2.5 has an annoying assert that seems to be a false alarm) and the version of SWIG 1.3.29 Robin uses for wxPython, available from here: NameBright - Coming Soon

You will need to build SWIG, but it is pretty much a configure / make / make install deal. Note that both Bakefile and SWIG should be available on your PATH.

Let me know if you run into any snags!

Thanks,

Kevin

--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 22:05, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 11:48 AM, Orestis Markou wrote:

Hi Kevin,

that looks exactly what I need. I have a Mac so it fits my needs 100%. Is this accessible in any of the release builds of wxPython or do I have to build my own from source?

You have to build from source for now. Once it's complete (i.e. also implemented on Win/Linux), I'm planning on moving it into the wx / wxPython build process so that it will be directly accessible via wxPython.

I will also have to test from Windows but it shouldn't be too hard to implement a similar interface (with some help, I don't have a clue about how wx is implemented), since the Win32 API has methods to create events like that.

mouse_event and keybd_event should allow us to implement these APIs. It shouldn't require too much knowledge about how wx is implemented, though, as you're mostly simulating native key and mouse events. There will probably be special work needed to handle non-ASCII characters, but I think even starting with ASCII support would be a huge plus. :slight_smile:

Thanks,

Kevin

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 18:33, Kevin Ollivier wrote:

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

wxTrac has been migrated to GitHub Issues - wxWidgets

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Orestis,

Hi again - I'm having a read through the documentation of the Quartz events[1] - it seems that CGPostKeyboardEvent is obsolete, and CGEventCreateKeyboardEvent should be used instead. My patch follows.

Thanks! :slight_smile: That code is a leftover from when I was still trying to have 10.3 support, but IIRC there were problems with mouse events using the old events.

From what I also gathered, converting from keycode/modifier to character depends on the keyboard layout. You can use UCKeyTranslate [2] to get the string from the keycode, but going the other way is more tricky. The Google Testing Toolkit has a translating function we could copy [3] (it's under the Apache 2.0 license).

Thanks, this looks like what I was trying to replicate myself. :wink: Unfortunately, from what I can read the Apache 2.0 license compatibility with LGPL 2 (and thus the wxWidgets license) is very murky territory.

There is also an interesting discussion at CocoaDev [4], which leads to a link to a .tgz file that has something that looks more robust (it's using the current keyboard layout and calls into some services, although my Objective-C-foo is non-existent so I may be talking nonsense). Unfortunately I've no idea how to progress from here.

I don't think KeyTranslate or the like is what we need here, because KeyTranslate is still working with the codes sent by the keyboard, which won't help us because we're not receiving actual keyboard presses. I think what we need is an ASCII -> virtual key code mapping (a mapping which does not vary by keyboard model), which is what the Google software gives us, but it looks like we'll need to create the same thing ourselves to be license compliant. I found a utility which will print out such a key combo for key presses, but I haven't figured out why saving the dictionary to disk is not working yet. Once I've got that done, I can create a mapping, perhaps one that is even more robust.

Thanks,

Kevin

···

On Jan 19, 2009, at 3:47 PM, Orestis Markou wrote:

Here's the patch:

Index: eventsim_mac.cpp

--- eventsim_mac.cpp (revision 58213)
+++ eventsim_mac.cpp (working copy)
@@ -47,6 +47,16 @@
    }
}

+void SendCharCode(CGCharCode keycode, bool isDown)
+{
+ CGEventRef event = CGEventCreateKeyboardEvent(NULL, keycode, isDown);
+ if (event)
+ {
+ CGEventPost(kCGHIDEventTap, event);
+ }
+ CFRelease(event);
+}
+
bool UIEventSimulator::MouseDown(int button)
{
    CGPoint pos;
@@ -107,20 +117,21 @@
bool UIEventSimulator::KeyPress(int keycode, bool isDown, bool shiftDown, bool cmdDown, bool altDown)
{
    if (shiftDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)56, true);
+ SendCharCode((CGCharCode)56, true);
    if (altDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)58, true);
+ SendCharCode((CGCharCode)58, true);
    if (cmdDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)55, true);
+ SendCharCode((CGCharCode)55, true);

- CGPostKeyboardEvent((CGCharCode)keycode, 0, isDown);
-
+ SendCharCode((CGCharCode)keycode, isDown);
+
    if (shiftDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)56, false);
+ SendCharCode((CGCharCode)56, false);
    if (altDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)58, false);
+ SendCharCode((CGCharCode)58, false);
    if (cmdDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)55, false);
+ SendCharCode((CGCharCode)55, false);
+
    return true;
}

[1]: http://developer.apple.com/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/func/CGEventCreateKeyboardEvent
[2]: http://developer.apple.com/documentation/Carbon/Reference/Unicode_Utilities_Ref/Reference/reference.html#//apple_ref/c/func/UCKeyTranslate
[3]: http://google-toolbox-for-mac.googlecode.com/svn/trunk/UnitTesting/GTMUnitTestingUtilities.m
[4]: http://www.cocoadev.com/index.pl?KeyCodesAndCharCodes
--
orestis@orestis.gr
http://orestis.gr/

On 19 Jan 2009, at 01:03, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 3:54 PM, Orestis Markou wrote:

That worked perfectly. I actually used bakefile 0.2.3 (available from MacPorts). Swig built cleanly and so did UIEventSimulator. I noticed that SendText isn't actually implemented, although it failed because it expected a wxString (?). Also, for some reason, the keypress/keychar functions always send 'a'. You can see it by changing your test to send and expect 'd'.

Looks like we need a way to map ASCII keys to 'virtual' key codes. What seems odd is that these codes are pretty much constant, but there isn't any mapping currently. There's an app that prints them, though, so I think I just need to alter it to spit them out to a sort of header file.

Anyway, thanks a lot! Am I correct to assume that _eventsim.so, libeventsim.dylib and eventsim.py are the only outputs? I'd like to check them in to my repo so I don't have to build them every time.

yes, that should be the case.

It also occurred to me that for win32, the relevant functions are probably exposed through the pywin32 extensions. I'll have a look tomorrow and send you the relevant info.

yes, it looks like they are. :slight_smile:

Thanks,

Kevin

Cheers,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 23:10, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 2:50 PM, Orestis Markou wrote:

I'll try building my own wxpython/wxwidgets. It seems like it's documented enough, hopefully I'll have no problems. How is UIEventSim built?

You actually shouldn't need to build your own wxWidgets/wxPython. As long as you have the wx-config for your wxPython on the PATH, it should build okay. Note that right now you also need Bakefile (I'd recommend getting 0.2.4 as 0.2.5 has an annoying assert that seems to be a false alarm) and the version of SWIG 1.3.29 Robin uses for wxPython, available from here: NameBright - Coming Soon

You will need to build SWIG, but it is pretty much a configure / make / make install deal. Note that both Bakefile and SWIG should be available on your PATH.

Let me know if you run into any snags!

Thanks,

Kevin

--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 22:05, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 11:48 AM, Orestis Markou wrote:

Hi Kevin,

that looks exactly what I need. I have a Mac so it fits my needs 100%. Is this accessible in any of the release builds of wxPython or do I have to build my own from source?

You have to build from source for now. Once it's complete (i.e. also implemented on Win/Linux), I'm planning on moving it into the wx / wxPython build process so that it will be directly accessible via wxPython.

I will also have to test from Windows but it shouldn't be too hard to implement a similar interface (with some help, I don't have a clue about how wx is implemented), since the Win32 API has methods to create events like that.

mouse_event and keybd_event should allow us to implement these APIs. It shouldn't require too much knowledge about how wx is implemented, though, as you're mostly simulating native key and mouse events. There will probably be special work needed to handle non-ASCII characters, but I think even starting with ASCII support would be a huge plus. :slight_smile:

Thanks,

Kevin

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 18:33, Kevin Ollivier wrote:

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

wxTrac has been migrated to GitHub Issues - wxWidgets

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Orestis,

I don't think KeyTranslate or the like is what we need here, because KeyTranslate is still working with the codes sent by the keyboard, which won't help us because we're not receiving actual keyboard presses. I think what we need is an ASCII -> virtual key code mapping (a mapping which does not vary by keyboard model), which is what the Google software gives us, but it looks like we'll need to create the same thing ourselves to be license compliant. I found a utility which will print out such a key combo for key presses, but I haven't figured out why saving the dictionary to disk is not working yet. Once I've got that done, I can create a mapping, perhaps one that is even more robust.

Sorry, what I meant was, to get the correct key code sequence that will generate an ASCII character, one has to factor the current keyboard layout. Example, if I, being Greek, select the Greek keyboard layout and then ask UIEventSim to send the latin character 'Q', there is no way for UIEventSim to do that (unless of course it changes the keyboard layout back to Latin).

I think that the last link (to CocoaDev) has a mechanism that looks in the keyboard tables and tries to work out which keycode you must use to generate a particular character (if I understand correctly - I haven't actually compiled it).

It also seems reasonable to add support for function/arrow keys, which don't map to any specific character. The Windows SendKeys function accepts {RETURN}, {SPC}, {LEFT} etc as valid inputs. I've no idea how it handles keyboard layouts - I'll have a look.

Orestis

···

On 20 Jan 2009, at 18:26, Kevin Ollivier wrote:

Thanks,

Kevin

Here's the patch:

Index: eventsim_mac.cpp

--- eventsim_mac.cpp (revision 58213)
+++ eventsim_mac.cpp (working copy)
@@ -47,6 +47,16 @@
   }
}

+void SendCharCode(CGCharCode keycode, bool isDown)
+{
+ CGEventRef event = CGEventCreateKeyboardEvent(NULL, keycode, isDown);
+ if (event)
+ {
+ CGEventPost(kCGHIDEventTap, event);
+ }
+ CFRelease(event);
+}
+
bool UIEventSimulator::MouseDown(int button)
{
   CGPoint pos;
@@ -107,20 +117,21 @@
bool UIEventSimulator::KeyPress(int keycode, bool isDown, bool shiftDown, bool cmdDown, bool altDown)
{
   if (shiftDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)56, true);
+ SendCharCode((CGCharCode)56, true);
   if (altDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)58, true);
+ SendCharCode((CGCharCode)58, true);
   if (cmdDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)55, true);
+ SendCharCode((CGCharCode)55, true);

- CGPostKeyboardEvent((CGCharCode)keycode, 0, isDown);
-
+ SendCharCode((CGCharCode)keycode, isDown);
+
   if (shiftDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)56, false);
+ SendCharCode((CGCharCode)56, false);
   if (altDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)58, false);
+ SendCharCode((CGCharCode)58, false);
   if (cmdDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)55, false);
+ SendCharCode((CGCharCode)55, false);
+
   return true;
}

[1]: http://developer.apple.com/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/func/CGEventCreateKeyboardEvent
[2]: http://developer.apple.com/documentation/Carbon/Reference/Unicode_Utilities_Ref/Reference/reference.html#//apple_ref/c/func/UCKeyTranslate
[3]: http://google-toolbox-for-mac.googlecode.com/svn/trunk/UnitTesting/GTMUnitTestingUtilities.m
[4]: http://www.cocoadev.com/index.pl?KeyCodesAndCharCodes
--
orestis@orestis.gr
http://orestis.gr/

On 19 Jan 2009, at 01:03, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 3:54 PM, Orestis Markou wrote:

That worked perfectly. I actually used bakefile 0.2.3 (available from MacPorts). Swig built cleanly and so did UIEventSimulator. I noticed that SendText isn't actually implemented, although it failed because it expected a wxString (?). Also, for some reason, the keypress/keychar functions always send 'a'. You can see it by changing your test to send and expect 'd'.

Looks like we need a way to map ASCII keys to 'virtual' key codes. What seems odd is that these codes are pretty much constant, but there isn't any mapping currently. There's an app that prints them, though, so I think I just need to alter it to spit them out to a sort of header file.

Anyway, thanks a lot! Am I correct to assume that _eventsim.so, libeventsim.dylib and eventsim.py are the only outputs? I'd like to check them in to my repo so I don't have to build them every time.

yes, that should be the case.

It also occurred to me that for win32, the relevant functions are probably exposed through the pywin32 extensions. I'll have a look tomorrow and send you the relevant info.

yes, it looks like they are. :slight_smile:

Thanks,

Kevin

Cheers,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 23:10, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 2:50 PM, Orestis Markou wrote:

I'll try building my own wxpython/wxwidgets. It seems like it's documented enough, hopefully I'll have no problems. How is UIEventSim built?

You actually shouldn't need to build your own wxWidgets/wxPython. As long as you have the wx-config for your wxPython on the PATH, it should build okay. Note that right now you also need Bakefile (I'd recommend getting 0.2.4 as 0.2.5 has an annoying assert that seems to be a false alarm) and the version of SWIG 1.3.29 Robin uses for wxPython, available from here: NameBright - Coming Soon

You will need to build SWIG, but it is pretty much a configure / make / make install deal. Note that both Bakefile and SWIG should be available on your PATH.

Let me know if you run into any snags!

Thanks,

Kevin

--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 22:05, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 11:48 AM, Orestis Markou wrote:

Hi Kevin,

that looks exactly what I need. I have a Mac so it fits my needs 100%. Is this accessible in any of the release builds of wxPython or do I have to build my own from source?

You have to build from source for now. Once it's complete (i.e. also implemented on Win/Linux), I'm planning on moving it into the wx / wxPython build process so that it will be directly accessible via wxPython.

I will also have to test from Windows but it shouldn't be too hard to implement a similar interface (with some help, I don't have a clue about how wx is implemented), since the Win32 API has methods to create events like that.

mouse_event and keybd_event should allow us to implement these APIs. It shouldn't require too much knowledge about how wx is implemented, though, as you're mostly simulating native key and mouse events. There will probably be special work needed to handle non-ASCII characters, but I think even starting with ASCII support would be a huge plus. :slight_smile:

Thanks,

Kevin

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 18:33, Kevin Ollivier wrote:

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

wxTrac has been migrated to GitHub Issues - wxWidgets

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Orestis,

Hi Orestis,

I don't think KeyTranslate or the like is what we need here, because KeyTranslate is still working with the codes sent by the keyboard, which won't help us because we're not receiving actual keyboard presses. I think what we need is an ASCII -> virtual key code mapping (a mapping which does not vary by keyboard model), which is what the Google software gives us, but it looks like we'll need to create the same thing ourselves to be license compliant. I found a utility which will print out such a key combo for key presses, but I haven't figured out why saving the dictionary to disk is not working yet. Once I've got that done, I can create a mapping, perhaps one that is even more robust.

Sorry, what I meant was, to get the correct key code sequence that will generate an ASCII character, one has to factor the current keyboard layout. Example, if I, being Greek, select the Greek keyboard layout and then ask UIEventSim to send the latin character 'Q', there is no way for UIEventSim to do that (unless of course it changes the keyboard layout back to Latin).

I'm not sure that's true if we're using virtual key codes, though we'd have to try it out to be sure.

I think that the last link (to CocoaDev) has a mechanism that looks in the keyboard tables and tries to work out which keycode you must use to generate a particular character (if I understand correctly - I haven't actually compiled it).

Which, IIUC, would be a layer above KeyPress, perhaps something that would go into SendChar. i.e. it sounds like it gives you a sequence of virtual key codes to pass to KeyPress to get a certain result.

It also seems reasonable to add support for function/arrow keys, which don't map to any specific character. The Windows SendKeys function accepts {RETURN}, {SPC}, {LEFT} etc as valid inputs. I've no idea how it handles keyboard layouts - I'll have a look.

Again, in my understanding, a virtual key code is simply a "universal" code for a particular key on a keyboard. Regardless of your keyboard layout or model, pressing that particular key will always generate the same code, which makes sense as it seems to me the only way you could write functions like KeyPress to begin with, which should not be restricted to text characters, but rather should be able to simulate any key on the keyboard.

Regards,

Kevin

···

On Jan 20, 2009, at 1:15 PM, Orestis Markou wrote:

On 20 Jan 2009, at 18:26, Kevin Ollivier wrote:

Orestis

Thanks,

Kevin

Here's the patch:

Index: eventsim_mac.cpp

--- eventsim_mac.cpp (revision 58213)
+++ eventsim_mac.cpp (working copy)
@@ -47,6 +47,16 @@
  }
}

+void SendCharCode(CGCharCode keycode, bool isDown)
+{
+ CGEventRef event = CGEventCreateKeyboardEvent(NULL, keycode, isDown);
+ if (event)
+ {
+ CGEventPost(kCGHIDEventTap, event);
+ }
+ CFRelease(event);
+}
+
bool UIEventSimulator::MouseDown(int button)
{
  CGPoint pos;
@@ -107,20 +117,21 @@
bool UIEventSimulator::KeyPress(int keycode, bool isDown, bool shiftDown, bool cmdDown, bool altDown)
{
  if (shiftDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)56, true);
+ SendCharCode((CGCharCode)56, true);
  if (altDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)58, true);
+ SendCharCode((CGCharCode)58, true);
  if (cmdDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)55, true);
+ SendCharCode((CGCharCode)55, true);

- CGPostKeyboardEvent((CGCharCode)keycode, 0, isDown);
-
+ SendCharCode((CGCharCode)keycode, isDown);
+
  if (shiftDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)56, false);
+ SendCharCode((CGCharCode)56, false);
  if (altDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)58, false);
+ SendCharCode((CGCharCode)58, false);
  if (cmdDown)
- CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)55, false);
+ SendCharCode((CGCharCode)55, false);
+
  return true;
}

[1]: http://developer.apple.com/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/func/CGEventCreateKeyboardEvent
[2]: http://developer.apple.com/documentation/Carbon/Reference/Unicode_Utilities_Ref/Reference/reference.html#//apple_ref/c/func/UCKeyTranslate
[3]: http://google-toolbox-for-mac.googlecode.com/svn/trunk/UnitTesting/GTMUnitTestingUtilities.m
[4]: http://www.cocoadev.com/index.pl?KeyCodesAndCharCodes
--
orestis@orestis.gr
http://orestis.gr/

On 19 Jan 2009, at 01:03, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 3:54 PM, Orestis Markou wrote:

That worked perfectly. I actually used bakefile 0.2.3 (available from MacPorts). Swig built cleanly and so did UIEventSimulator. I noticed that SendText isn't actually implemented, although it failed because it expected a wxString (?). Also, for some reason, the keypress/keychar functions always send 'a'. You can see it by changing your test to send and expect 'd'.

Looks like we need a way to map ASCII keys to 'virtual' key codes. What seems odd is that these codes are pretty much constant, but there isn't any mapping currently. There's an app that prints them, though, so I think I just need to alter it to spit them out to a sort of header file.

Anyway, thanks a lot! Am I correct to assume that _eventsim.so, libeventsim.dylib and eventsim.py are the only outputs? I'd like to check them in to my repo so I don't have to build them every time.

yes, that should be the case.

It also occurred to me that for win32, the relevant functions are probably exposed through the pywin32 extensions. I'll have a look tomorrow and send you the relevant info.

yes, it looks like they are. :slight_smile:

Thanks,

Kevin

Cheers,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 23:10, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 2:50 PM, Orestis Markou wrote:

I'll try building my own wxpython/wxwidgets. It seems like it's documented enough, hopefully I'll have no problems. How is UIEventSim built?

You actually shouldn't need to build your own wxWidgets/wxPython. As long as you have the wx-config for your wxPython on the PATH, it should build okay. Note that right now you also need Bakefile (I'd recommend getting 0.2.4 as 0.2.5 has an annoying assert that seems to be a false alarm) and the version of SWIG 1.3.29 Robin uses for wxPython, available from here: NameBright - Coming Soon

You will need to build SWIG, but it is pretty much a configure / make / make install deal. Note that both Bakefile and SWIG should be available on your PATH.

Let me know if you run into any snags!

Thanks,

Kevin

--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 22:05, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 11:48 AM, Orestis Markou wrote:

Hi Kevin,

that looks exactly what I need. I have a Mac so it fits my needs 100%. Is this accessible in any of the release builds of wxPython or do I have to build my own from source?

You have to build from source for now. Once it's complete (i.e. also implemented on Win/Linux), I'm planning on moving it into the wx / wxPython build process so that it will be directly accessible via wxPython.

I will also have to test from Windows but it shouldn't be too hard to implement a similar interface (with some help, I don't have a clue about how wx is implemented), since the Win32 API has methods to create events like that.

mouse_event and keybd_event should allow us to implement these APIs. It shouldn't require too much knowledge about how wx is implemented, though, as you're mostly simulating native key and mouse events. There will probably be special work needed to handle non-ASCII characters, but I think even starting with ASCII support would be a huge plus. :slight_smile:

Thanks,

Kevin

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 18:33, Kevin Ollivier wrote:

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

wxTrac has been migrated to GitHub Issues - wxWidgets

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

I think we are saying the same thing, in different words :slight_smile:

Anyway, my concern is that a high-level function such as SendChar is going to be very tricky to implement because it is dependent on the keyboard layout.

A PressKey function can clearly say: "This simulates a finger pressing the requested key on the current keyboard. We don't care what the OS or your app do with it".

Forgive my ignorance - if I duplicate the eventsim_mac.cpp to eventsim_win32.cpp, add the necessary header imports, change the necessary #ifs, is it just a matter of plumbing the correct win32 calls in the correct places of the UISimulator class? Will building do the correct thing?

BTW, if this gets implementations on the linux & win32, what is the procedure of moving it to the official wxpython?

Cheers,
Orestis

···

On 20 Jan 2009, at 22:23, Kevin Ollivier wrote:

Again, in my understanding, a virtual key code is simply a "universal" code for a particular key on a keyboard. Regardless of your keyboard layout or model, pressing that particular key will always generate the same code, which makes sense as it seems to me the only way you could write functions like KeyPress to begin with, which should not be restricted to text characters, but rather should be able to simulate any key on the keyboard.

--
orestis@orestis.gr

While this surely sounds safe and implementable it may still
not be easy: It may need to inject data below the lowest
layer of kernel keyboard drivers which can be about as close
to the bare metal as it gets regarding keyboard input.

Nonetheless this would be extremely useful.

Karsten

···

On Thu, Jan 22, 2009 at 12:01:13AM +0000, Orestis Markou wrote:

Anyway, my concern is that a high-level function such as SendChar is
going to be very tricky to implement because it is dependent on the
keyboard layout.

A PressKey function can clearly say: "This simulates a finger pressing
the requested key on the current keyboard. We don't care what the OS or
your app do with it".

--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

Hi Orestis,

Again, in my understanding, a virtual key code is simply a "universal" code for a particular key on a keyboard. Regardless of your keyboard layout or model, pressing that particular key will always generate the same code, which makes sense as it seems to me the only way you could write functions like KeyPress to begin with, which should not be restricted to text characters, but rather should be able to simulate any key on the keyboard.

I think we are saying the same thing, in different words :slight_smile:

Anyway, my concern is that a high-level function such as SendChar is going to be very tricky to implement because it is dependent on the keyboard layout.

A PressKey function can clearly say: "This simulates a finger pressing the requested key on the current keyboard. We don't care what the OS or your app do with it".

Yes, sorry, I should just remove SendChar for now as I agree it will be tricky to implement it in a robust way.

Forgive my ignorance - if I duplicate the eventsim_mac.cpp to eventsim_win32.cpp, add the necessary header imports, change the necessary #ifs, is it just a matter of plumbing the correct win32 calls in the correct places of the UISimulator class? Will building do the correct thing?

On Linux, yes, for MSW we'll need to tweak the build script a bit. Shouldn't be anything too major, though. I've added Linux and MSW stubs to the tree and added them to the build scripts to head off some of the work that needs done. :slight_smile:

BTW, if this gets implementations on the linux & win32, what is the procedure of moving it to the official wxpython?

I'll probably ask Robin, and he'll be like "sure, whatever" and I be like "awesome", unless he's all like "dude, no way!" and then I'll be like "bummer!". In short, it's a pretty informal process so long as the code uses the wxWindows license. :slight_smile: I suspect Robin is already aware of my intentions and he hasn't stopped me, so... :wink:

Regards,

Kevin

···

On Jan 21, 2009, at 4:01 PM, Orestis Markou wrote:

On 20 Jan 2009, at 22:23, Kevin Ollivier wrote:

Cheers,
Orestis

--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Kevin Ollivier wrote:

BTW, if this gets implementations on the linux & win32, what is the procedure of moving it to the official wxpython?

I'll probably ask Robin, and he'll be like "sure, whatever" and I be like "awesome", unless he's all like "dude, no way!" and then I'll be like "bummer!".

Duuuuude, you're so, like, seeing inside my head.

> In short, it's a pretty informal process so long as the

code uses the wxWindows license. :slight_smile: I suspect Robin is already aware of my intentions and he hasn't stopped me, so... :wink:

Looking forward to it actually. There's also some code from OSAF that can be used for recording mouse and keyboard events in a wxPython app that they used for testing. Their playback of those events used higher level Chandler-specific stuff, but combining it with your lower-level event injection would be lots better and more general purpose.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi, after painstaking trial-end-error (you really don't want to press all the function keys that control brightness in an automated way!), I have this:

t000_54 = [97, 115, 100, 102, 104, 103, 122, 120, 99, 118, 164, 98, 113, 119, 101, 114, 121, 116, 49, 50, 51, 52, 54, 53, 61, 57, 55, 45, 56, 48, 93, 111, 117, 91, 105, 112, 13, 108, 106, 39, 107, 59, 92, 44, 47, 110, 109, 46, 9, 32, 96, 8, 13, 27]

t054_65 = [None] * 11

t065_68 = [46, 316, 42]

t068_69 = [None]

t069_73 = [43, 314, 27, 317]

t073_75 = [None] * 2

t075_79 = [47, 13, 315, 45]

t079_81 = [None] * 2

t081_90 = [61, 48, 49, 50, 51, 52, 53, 54, 55]

t090_91 = [None]

t091_93 = [56, 57]

t093_96 = [None] * 3

t096_100 = [344, 345, 346, 342]

t100_101 = [None] # F8
t101_102 = [None] # F9

t102_103 = [None]
t103_104 = [None] # perhaps f11
t104_105 = [None] # perhaps f11
t105_107 = [352, 16]
t107_108 = [None] # F2
t108_109 = [16]
t109_110 = [None]
t110_111 = [16]
t111_112 = [None]
t112_113 = [16]
t113_114 = [None]
t114_115 = [323]

t115_127 = [313, 366, 127, 343, 312, 341, 367, 340, 314, 316, 317, 315]

tables = [k for k in locals().keys() if k.startswith('t')]
tables.sort()

master_table =
for t in tables:
     master_table.extend(locals()[t])

reverse_table = {}
for idx, code in enumerate(master_table):
     if code is not None:
         try:
             reverse_table[unichr(code)] = idx
         except:
             print 'idx, code %s, %s not unichrable' % (idx, code)
     else:
         print 'idx %s is None' % idx

from pprint import pprint
pprint(reverse_table)

Which at least contains most ASCII characters. Generated using a US layout:

{u'\x08': 51,
  u'\t': 48,
  u'\r': 76,
  u'\x10': 112,
  u'\x1b': 71,
  u' ': 49,
  u"'": 39,
  u'*': 67,
  u'+': 69,
  u',': 43,
  u'-': 78,
  u'.': 65,
  u'/': 75,
  u'0': 82,
  u'1': 83,
  u'2': 84,
  u'3': 85,
  u'4': 86,
  u'5': 87,
  u'6': 88,
  u'7': 89,
  u'8': 91,
  u'9': 92,
  u';': 41,
  u'=': 81,
  u'[': 33,
  u'\\': 42,
  u']': 30,
  u'`': 50,
  u'a': 0,
  u'b': 11,
  u'c': 8,
  u'd': 2,
  u'e': 14,
  u'f': 3,
  u'g': 5,
  u'h': 4,
  u'i': 34,
  u'j': 38,
  u'k': 40,
  u'l': 37,
  u'm': 46,
  u'n': 45,
  u'o': 31,
  u'p': 35,
  u'q': 12,
  u'r': 15,
  u's': 1,
  u't': 17,
  u'u': 32,
  u'v': 9,
  u'w': 13,
  u'x': 7,
  u'y': 16,
  u'z': 6,
  u'\x7f': 117,
  u'\xa4': 10,
  u'\u0138': 119,
  u'\u0139': 115,
  u'\u013a': 123,
  u'\u013b': 126,
  u'\u013c': 124,
  u'\u013d': 125,
  u'\u0143': 114,
  u'\u0154': 122,
  u'\u0155': 120,
  u'\u0156': 99,
  u'\u0157': 118,
  u'\u0158': 96,
  u'\u0159': 97,
  u'\u015a': 98,
  u'\u0160': 105,
  u'\u016e': 116,
  u'\u016f': 121}

These are all keycodes as captured by the OnChar event, as wired up in tests/testButton.py. There is a also a number of other events that are not captured at all, and will need even more trial and error to decode. The fact that the function keys are "special" on my MacBook doesn't help.

Hopefully this is going to be helpful.

Orestis

···

--
orestis@orestis.gr

On 19 Jan 2009, at 01:03, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 3:54 PM, Orestis Markou wrote:

That worked perfectly. I actually used bakefile 0.2.3 (available from MacPorts). Swig built cleanly and so did UIEventSimulator. I noticed that SendText isn't actually implemented, although it failed because it expected a wxString (?). Also, for some reason, the keypress/keychar functions always send 'a'. You can see it by changing your test to send and expect 'd'.

Looks like we need a way to map ASCII keys to 'virtual' key codes. What seems odd is that these codes are pretty much constant, but there isn't any mapping currently. There's an app that prints them, though, so I think I just need to alter it to spit them out to a sort of header file.

Anyway, thanks a lot! Am I correct to assume that _eventsim.so, libeventsim.dylib and eventsim.py are the only outputs? I'd like to check them in to my repo so I don't have to build them every time.

yes, that should be the case.

It also occurred to me that for win32, the relevant functions are probably exposed through the pywin32 extensions. I'll have a look tomorrow and send you the relevant info.

yes, it looks like they are. :slight_smile:

Thanks,

Kevin

Cheers,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 23:10, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 2:50 PM, Orestis Markou wrote:

I'll try building my own wxpython/wxwidgets. It seems like it's documented enough, hopefully I'll have no problems. How is UIEventSim built?

You actually shouldn't need to build your own wxWidgets/wxPython. As long as you have the wx-config for your wxPython on the PATH, it should build okay. Note that right now you also need Bakefile (I'd recommend getting 0.2.4 as 0.2.5 has an annoying assert that seems to be a false alarm) and the version of SWIG 1.3.29 Robin uses for wxPython, available from here: NameBright - Coming Soon

You will need to build SWIG, but it is pretty much a configure / make / make install deal. Note that both Bakefile and SWIG should be available on your PATH.

Let me know if you run into any snags!

Thanks,

Kevin

--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 22:05, Kevin Ollivier wrote:

Hi Orestis,

On Jan 18, 2009, at 11:48 AM, Orestis Markou wrote:

Hi Kevin,

that looks exactly what I need. I have a Mac so it fits my needs 100%. Is this accessible in any of the release builds of wxPython or do I have to build my own from source?

You have to build from source for now. Once it's complete (i.e. also implemented on Win/Linux), I'm planning on moving it into the wx / wxPython build process so that it will be directly accessible via wxPython.

I will also have to test from Windows but it shouldn't be too hard to implement a similar interface (with some help, I don't have a clue about how wx is implemented), since the Win32 API has methods to create events like that.

mouse_event and keybd_event should allow us to implement these APIs. It shouldn't require too much knowledge about how wx is implemented, though, as you're mostly simulating native key and mouse events. There will probably be special work needed to handle non-ASCII characters, but I think even starting with ASCII support would be a huge plus. :slight_smile:

Thanks,

Kevin

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

On 18 Jan 2009, at 18:33, Kevin Ollivier wrote:

Hi Ivan, Orestis,

I've actually been working towards a wx(Python) extension to encapsulate these platform methods into a helper library that can be used to improve the wxPython unit tests. The API is designed and should work cross-platform, but I only have the Mac impl. so far.

wxTrac has been migrated to GitHub Issues - wxWidgets

Ivan, did you just write that code sample up or have you created a similar Python binding for Linux?

Thanks,

Kevin

On Jan 18, 2009, at 9:51 AM, Ivan Nazarenko wrote:

My guess is that you do not synthesize keyboards events directly in wx
because you don't need to, since under linux you have the XTest
extension to do just that. The source code is attached. Run setup to
compile keymodule and have the resulting keymodule.so visible (in your
current directory, for instance).

On windows, though, I still haven't had to synthesize them, so I am
not aware how to do it.

Regards.

PS: to use it, open thread different from the user interface, and
from this thread:

import key

...
  key.makeev(kc) # get kc from /usr/include/X11/keysymdef.h

That's it. "man XTestFakeKeyEvent" have some info on it.

On 1/18/09, Orestis Markou <orestis@orestis.gr> wrote:

Hello,

from browsing the archives, it seems that simulating events is tricky
and can't be done from wxpython. I can live with that for mouse
events, which are tricky to get right in any case, but keyboard events
would be very handy during testing.

Is there any reasonable way of synthesising and sending a keyboard
event to the application, so that all the codepaths (including focus
etc) are exercised during a test run? Or native events *have* to be
synthesised? I am using the STC widget along some other simple text
ctrls.

Thanks,
Orestis
--
orestis@orestis.gr
http://orestis.gr/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

<keymodule.c><setup.py>_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users