俊星的BLOG
導航
BlogJava
首頁
新隨筆
聯系
聚合
管理
<
2009年6月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
統計
隨筆 - 50
文章 - 0
評論 - 6
引用 - 0
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(1)
給我留言
查看公開留言
查看私人留言
隨筆分類
代碼庫(7)
(rss)
隨筆檔案
2010年11月 (3)
2010年10月 (12)
2009年6月 (5)
2009年5月 (22)
2009年4月 (8)
最新隨筆
1.?實現變更統計
2.?切換IE8中碰到的問題
3.?發布FWMS
4.?ActiveMQ初探
5.?CAS初步配置
搜索
最新評論
1.?re: JAVA圖像縮放處理[未登錄]
不錯的方法
--test
2.?re: freetts初探
學習了! 就是不清楚為啥在eclipse下跑不起來...
--apiao
3.?re: freetts初探
System property "mbrola.base" is undefined. Will not use MBROLA voices.
這個問題怎么解決啊?
--瓏兒
4.?re: ActiveMQ初探
測試通過。多謝
--71569973
5.?登錄網站
評論內容較長,點擊標題查看
--ahome
閱讀排行榜
1.?ftp的port和pasv模式(轉)(8036)
2.?JAVA圖像縮放處理(4187)
3.?Nutz初步試用(4110)
4.?Window下FTP命令使用(3523)
5.?freetts初探(3436)
6.?ActiveMQ初探(2910)
7.?MYSQL Access denied 問題的解決(2347)
8.?HTTP Client及HTTPS初探(1993)
9.?JAVA單向加密(MD5,SHA,MAC)(1269)
10.?CAS認證初探(1159)
評論排行榜
1.?freetts初探(2)
2.?HTTP Client及HTTPS初探(2)
3.?ActiveMQ初探(1)
4.?JAVA圖像縮放處理(1)
5.?我的DWR之DefaultContainer(0)
SWT試用之控制鼠標鍵盤
通過SWT可以控制鼠標鍵盤事件,具體如下:
import
org.eclipse.swt.SWT;
import
org.eclipse.swt.widgets.Display;
import
org.eclipse.swt.widgets.Event;
import
org.eclipse.swt.widgets.Shell;
import
org.eclipse.swt.widgets.Text;
/** */
/**
* 預期的運行效果為:顯示開始菜單
*
@author
kinkding
* @history 2009-6-2
*/
public
class
MyEventRes
{
public
static
void
main(String[] args)
{
final
Display display
=
new
Display();
final
Shell shell
=
new
Shell(display);
final
Text text
=
new
Text(shell, SWT.BORDER);
text.setSize(text.computeSize(
150
, SWT.DEFAULT));
text.setText(
"
神一樣的人啊!
"
);
shell.pack();
shell.open();
new
KeyThread(display).start();
//
鍵盤響應
//
new MouseThread(display).start();
//
鼠標響應
while
(
!
shell.isDisposed())
{
if
(
!
display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
class
MouseThread
extends
Thread
{
Display display;
int
h;
public
MouseThread(Display display)
{
this
.display
=
display;
h
=
display.getPrimaryMonitor().getBounds().height;
}
public
void
run()
{
Event event
=
new
Event();
//
移動鼠標
event.type
=
SWT.MouseMove;
event.x
=
5
;
event.y
=
h
-
5
;
display.post(event);
try
{
Thread.sleep(
100
);
}
catch
(InterruptedException e)
{
}
//
按下右鍵
event.type
=
SWT.MouseDown;
event.button
=
1
;
display.post(event);
try
{
Thread.sleep(
100
);
}
catch
(InterruptedException e)
{
}
//
恢復
event.type
=
SWT.MouseUp;
display.post(event);
}
}
class
KeyThread
extends
Thread
{
Display display;
int
h;
public
KeyThread(Display display)
{
this
.display
=
display;
h
=
display.getPrimaryMonitor().getBounds().height;
}
public
void
run()
{
Event event
=
new
Event();
//
按下CTRL
event.type
=
SWT.KeyDown;
event.keyCode
=
SWT.CTRL;
display.post(event);
try
{
Thread.sleep(
100
);
}
catch
(InterruptedException e)
{
}
//
按下ESC
event.type
=
SWT.KeyDown;
event.keyCode
=
SWT.ESC;
display.post(event);
try
{
Thread.sleep(
100
);
}
catch
(InterruptedException e)
{
}
//
恢復
event.type
=
SWT.KeyUp;
event.keyCode
=
SWT.CTRL;
display.post(event);
try
{
Thread.sleep(
100
);
}
catch
(InterruptedException e)
{
}
event.type
=
SWT.KeyUp;
event.keyCode
=
SWT.ESC;
display.post(event);
}
}
posted on 2009-06-02 00:15
俊星
閱讀(823)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Powered by:
BlogJava
Copyright © 俊星
主站蜘蛛池模板:
延边
|
安顺市
|
酉阳
|
江西省
|
会昌县
|
吐鲁番市
|
凤翔县
|
齐齐哈尔市
|
铁岭县
|
新田县
|
万源市
|
孝感市
|
北流市
|
手机
|
东至县
|
汝城县
|
尤溪县
|
南康市
|
承德市
|
恭城
|
荣昌县
|
金溪县
|
嘉兴市
|
乌苏市
|
永顺县
|
新民市
|
南木林县
|
孟津县
|
平遥县
|
湖口县
|
赤水市
|
郸城县
|
拉萨市
|
营口市
|
娄底市
|
八宿县
|
江阴市
|
酒泉市
|
墨脱县
|
三河市
|
岢岚县
|