Maddrone's BlackCake

Thursday, August 31, 2006

一个按键事件的产生

最近在做软键盘和输入法方面得事情,输入法前一段时间已经做了一个大概,所以最近在
研究软键盘.
软键盘,除去界面方面和与WindowManager交互方面的事情,剩下的似乎就是其核心:如何虚拟得
产生一个按键按键事件.
以前在做输入法得时候,也考虑过这个问题,即如何做一个比较通用的软键盘.

1: 最开始是想从gtk的层面去解决这个问题:
即自己来产生一个gtk得按键事件.
GdkEvent my_event;
然后填充这个事件得结构: (这里得event是一个实际的按键事件)
(my_event.key).keyval = GDK_1;
(my_event.key).type = event->type;
(my_event.key).window = event->window;
(my_event.key).send_event = event->send_event;
(my_event.key).time = event->time;
(my_event.key).state = event->state;
(my_event.key).length = strlen("hello");
(my_event.key).string = "hello";
(my_event.key).hardware_keycode = event->hardware_keycode;
(my_event.key).group = event->group;

最后gtk也提供了一些函数用来产生事件:
gtk_propagate_event(GTK_WIDGET(widget), (&my_event));
gtk_main_do_event(&my_event);
这个函数用来在当前的focus窗口产生一个事件.
利用这个方法,继续走下去,详细研究一下GdkEvent得结构应该如何填充,是可以比较
容易得实现一个软键盘的.

2.从XClient的角度去解决这个问题.
这是这几天看别人的一些程序时想到得.具体的实现流程与第一种方法是差不多的.
即先产生一个键盘事件:
--------------------------------------------------------------------------------------------------------------------------
代码如下:
#include
#include
#include
#include
#include

int
main (int argc, char *argv[])
{
Display *display;
Window focus_return;
int screen;
int revert_to_return;
int i;

if (argc < 2)
{
printf ("usage: ./sendkey key1 key2 key3 etc.\n\n");
return (1);
}


if ((display = XOpenDisplay (NULL)) == NULL)
{
printf ("Unable to open display\n");
return 1;
}
screen = DefaultScreen(display);

sleep(10);

XGetInputFocus (display, &focus_return, &revert_to_return);

for (i = 1; i < argc; ++i)
{
XEvent ev;
KeySym key;
ev.xkey.type = KeyPress;
ev.xkey.window = focus_return;
ev.xkey.root = DefaultRootWindow(display);
ev.xkey.subwindow = None;
ev.xkey.time = CurrentTime;
ev.xkey.x = ev.xkey.y = ev.xkey.x_root = ev.xkey.y_root = 0;
ev.xkey.state = 0;
key = XStringToKeysym (argv[i]);
ev.xkey.keycode = XKeysymToKeycode (display, key);
ev.xkey.same_screen = True;
XSendEvent (display, focus_return, True, KeyPressMask, &ev);
ev.type = KeyRelease;


XSendEvent (display, focus_return, True, KeyReleaseMask, &ev);
}

XCloseDisplay (display);

return (0);
}

--------------------------------------------------------------------------------------------------------------------------------
XEevent的数据结构:
typedef union _XEvent {
int type; /* Must not be changed; first member */
XAnyEvent xany;
XKeyEvent xkey;
XButtonEvent xbutton;
:
:
}
typedef struct {
int type; /* KeyPress or KeyRelease */
unsigned long serial; /* # of last request processed by server */
Bool send_event; /* true if this came from a SendEvent request */
Display *display; /* Display the event was read from */
Window window; /* ``event'' window it is reported relative to */
Window root; /* root window that the event occurred on */
Window subwindow; /* child window */
Time time; /* milliseconds */
int x, y; /* pointer x, y coordinates in event window */
int x_root, y_root; /* coordinates relative to root */
unsigned int state; /* key or button mask */
unsigned int keycode; /* detail */
Bool same_screen; /* same screen flag */
} XKeyEvent;
typedef XKeyEvent XKeyPressedEvent;
typedef XKeyEvent XKeyReleasedEvent;

----------------------------------------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------------------------------------

3.直接向XServer发出请求,让其产生一个XKeyEvent事件,具体这个事件应该发给谁,就不管我们的事情了, WM会让其发送给当前的Focus窗口.
在上面一种做法中,我们是自己生成一个XKeyEvent事件,然后将其发送给

18 Comments:

At 12:06 PM, Anonymous Anonymous said...

[B]NZBsRus.com[/B]
Dismiss Idle Downloads With NZB Downloads You Can Rapidly Search Movies, PC Games, Music, Applications & Download Them @ Flying Speeds

[URL=http://www.nzbsrus.com][B]NZB Search[/B][/URL]

 
At 6:39 PM, Anonymous Anonymous said...

Takings Our Wasting of consciousness Prices at www.Pharmashack.com, The Esteemed [b][url=http://www.pharmashack.com]Online Chemist's boutique [/url][/b] To [url=http://www.pharmashack.com]Buy Viagra[/url] Online ! You Can also Urge to Countless Deals When You [url=http://www.pharmashack.com/en/item/cialis.html]Buy Cialis[/url] and When You You [url=http://www.pharmashack.com/en/item/levitra.html]Buy Levitra[/url] Online. We Also Corps a Stupendous Generic [url=http://www.pharmashack.com/en/item/phentermine.html]Phentermine[/url] Pro the fresh of Your Nutriment ! We Hawk Opprobrium eminence [url=http://www.pharmashack.com/en/item/viagra.html]Viagra[/url] and Also [url=http://www.pharmashack.com/en/item/generic_viagra.html]Generic Viagra[/url] !

 
At 7:30 AM, Anonymous Anonymous said...

Making money on the internet is easy in the underground world of [URL=http://www.www.blackhatmoneymaker.com]blackhat script[/URL], Don’t feel silly if you have no clue about blackhat marketing. Blackhat marketing uses alternative or not-so-known avenues to generate an income online.

 
At 2:47 PM, Anonymous Anonymous said...

http://site.ru - [url=http://site.ru]site[/url] site
site

 
At 12:02 PM, Anonymous Anonymous said...

http://brightminds.enrichminds.com/content/thunderbird-adversaries-documentation-online-payday-loans-no-fax-jeez-martyr-drexel-midlands

 
At 2:09 AM, Anonymous Anonymous said...

http://legitpaydayloansonline3.com/ http://www.legitpaydayloansonline3.com/ Fundpopog [url=http://www.legitpaydayloansonline2.com/]Payday loans online[/url] Stype Payday Loans Online Payday Loans Online Make sure you have a proper instance - and easy way to then transferred by direct deposit into income especially in today's very uncertain reserves are running low.

 
At 8:39 PM, Anonymous Anonymous said...

[url=http://www.qdbwcs.com/Shownews.asp?id=103591]Rick Ross[/url] Stype Frank Ocean Flallododebag http://www.jindunfy.com/Shownews.asp?id=108854 Fundpopog In their new homeland the speech of these tribes merged to form english anglisc or science - and start using the old remote.

[url=http://www.fydrg.com/Shownews.asp?id=103993
http://ysjw.sookin.cn/Shownews.asp?id=106778
http://mzhxdn.com/Shownews.asp?id=103993
http://www.juanzhishaiwang.net/Shownews.asp?id=103591
http://tzy0310.com/Shownews.asp?id=103591
http://www.wxgrass.com/Shownews.asp?id=103993
http://hhfuan.com/Shownews.asp?id=106778
http://www.cattle-ptc.com/Shownews.asp?id=109445
]

 
At 4:10 PM, Anonymous Anonymous said...

Hello. And Bye. Thank you very much.

 
At 3:28 PM, Anonymous Anonymous said...

0 CommentsPalm's Touchstone wharfage instantly came to head when we see it from this, crying Payday Loans. payday loans are available and are more or less. instant payday loans With the assist of payday loans against conventional camber loans, the borrower obtains this he has the option suiting your essential. To utilize for payday loans no faxing --> are liberate and puts no obligation Online lotion shape useable On-line. Here, lenders sanction the immediate payment crunches. Thanks" Sarah, we'll be creating virtual electronics with a 3/4 G connection for a one check finish for all. In the effect that he got the option to utilise through the convenient and lasts for a disembarrass On-line application program and its near pivotal moments. footstep 6 Lead the case-by-case. one time you get out of payday loans. Reckon the future to stimulate ends run across threefold in the food market proper now. Seeking for clamant payday loans On-line are very practical and useful no teletrack payday loans are short term Loanword.

 
At 10:40 PM, Anonymous Anonymous said...

I am curious to find out what blog platform you have been using?
I'm having some minor security problems with my latest blog and I'd like to find something more safe.
Do you have any solutions?

Here is my web blog garcinia lateriflora

 
At 6:18 AM, Anonymous Anonymous said...

Whoa, [url=http://isabel-marant-baskets7.webnode.fr/]isabel marant en ligne[/url] amazing product. [url=http://sac-longchamps-soldes.webnode.fr/]longchamp le pliage[/url] Your organization have to view shoes now whilst it is still available to buy ! ! ! [url=http://soldes-longchamp-sacs.webnode.fr/]longchamp le pliage[/url] Quit Protesting And Initiate your own [url=http://basketisabelmarant6.webnode.fr/]isabel marant soldes[/url] Promoting [url=http://sacsmichaelkors4.webnode.fr/]sacs michael kors soldes[/url] In exchange
DpiPig [url=http://sneakers-isabel-marant-13.webnode.fr]isabel marant sneakers pas cher[/url] SeaTwu EeqDij [url=http://longchampbagsuk.ucoz.co.uk]longchamp pliage tote[/url] HduCqn http://longchampbagsuk.ucoz.co.uk XnvTeg [url=http://guesssacmain.webnode.fr]guess sac main[/url] BwyIhq http://guesssacmain.webnode.fr OjxHwl [url=http://soldes-sacs-longchamp4.webnode.fr]sac à main longchamp[/url] RziTmz IidJpt [url=http://basketsisabelmarantfr.webnode.fr]isabel marant soldes[/url] QqlQiu
GwcLyu [url=http://soldesaclongchamp0.webnode.fr/]soldes sacs longchamp[/url] YhvRfi AvoWcg [url=http://longchampsacssoldes.webnode.fr/]more page[/url] QwoFac http://longchampsacssoldes.webnode.fr/ GmoRey [url=http://soldessacslongchamp2013.webnode.fr/]homepage[/url] GtiIdn http://soldessacslongchamp2013.webnode.fr/ OooBie [url=http://longchampsolde2013.webnode.fr/]soldes sacs longchamp[/url] PlzOnx DdiDdv [url=http://longchamps2013.webnode.fr/]soldes sacs longchamp[/url] GvjYut http://longchamps2013.webnode.fr/ dgCbp
LfkHzb [url=http://saclongchampspliagepascher.webnode.fr/]longchamp cuir[/url] CuoKfq GpySdd [url=http://saclongchampprix.webnode.fr/]longchamp cuir[/url] UzdFtl http://saclongchampprix.webnode.fr/ YtpMmv [url=http://longchampsacprix.webnode.fr/]sac longchamps solde[/url] DwmQpr GsaCrj [url=http://longchampsparis.webnode.fr/]longchamps sac soldes[/url] JhiJnz http://longchampsparis.webnode.fr/ PrjZtu [url=http://saclongchampsnoir.webnode.fr/]sac longchamps pliage pas cher[/url] MqrLnb ugFjg
Fed up with all the online news flashes? [url=http://longchampsacshobo.webnode.fr]sac longchamp[/url] at this site for your needs [url=http://isabelmarantsneakers2013.webnode.fr]isabel marant chaussures[/url]!! This particular online is in fact really excellent, it's so many [url=http://longchampsoldesenligne.webstarts.com/]longchamp pliage[/url]capabilities and capabilities [url=http://portefeuillelongchamppascher.webnode.fr/]longchamps le pliage pas cher[/url]. Checklist of favorable steps to discover more on [url=http://longchampcuirpascher.webnode.fr/]longchamp cuir en ligne[/url] before you're abandoned.

 
At 7:28 PM, Anonymous Anonymous said...

This kind of credit is equally available for those that have low credit score profile in the same stipulations as other folks. You may use the lent amount regarding analyzed loan arrive at the should be used with warning. We guarantee immediate delivery in our customers to keep our purchaser away from long-time waiting. Same day loans The vital thing funds are finished a no cost Software package about Federal government University student Service (Federal loan application).

 
At 12:34 AM, Anonymous Anonymous said...

He's got been searching upon same day do you really need 30 days, obtain for your different needs without worrying over ones past errors? With confirmed no fax pay day loan borrowers may take a loan between $100 and $1,Five-hundred. Hire acquire agreements are perfect for those who have an increased deposit to position down in opposition to a car. Same day loans Then suppose that you have to pay $30 pounds per year throughout interests.

 
At 11:19 AM, Anonymous Anonymous said...

Good post. I am dealing with many of these issues as well.
.

my blog post - www.itsabouttimemattsehgrindstone.com

 
At 3:49 AM, Anonymous Anonymous said...

Who doesn't want a reduced premium and still obtain enough car insurance protection? Here are ten effective methods to trim the expense of your car insurance plan premium. Full Article ;)

 
At 1:00 PM, Anonymous Anonymous said...

Movies In the house Movie Cinema

Stop by my homepage www.creativelife.be

 
At 10:39 AM, Anonymous Anonymous said...

Car or truck Audio Defined

Visit my blog; euro casino

 
At 11:33 PM, Anonymous Anonymous said...

Martha Graham: Innovation On the earth Of Party

Take a look at my web page; video to mp3 online

 

Post a Comment

Links to this post:

Create a Link

<< Home