请教GUI 里能否用电脑开机键盘鼠标不亮键盘控制鼠标

新手园地& & & 硬件问题Linux系统管理Linux网络问题Linux环境编程Linux桌面系统国产LinuxBSD& & & BSD文档中心AIX& & & 新手入门& & & AIX文档中心& & & 资源下载& & & Power高级应用& & & IBM存储AS400Solaris& & & Solaris文档中心HP-UX& & & HP文档中心SCO UNIX& & & SCO文档中心互操作专区IRIXTru64 UNIXMac OS X门户网站运维集群和高可用服务器应用监控和防护虚拟化技术架构设计行业应用和管理服务器及硬件技术& & & 服务器资源下载云计算& & & 云计算文档中心& & & 云计算业界& & & 云计算资源下载存储备份& & & 存储文档中心& & & 存储业界& & & 存储资源下载& & & Symantec技术交流区安全技术网络技术& & & 网络技术文档中心C/C++& & & GUI编程& & & Functional编程内核源码& & & 内核问题移动开发& & & 移动开发技术资料ShellPerlJava& & & Java文档中心PHP& & & php文档中心Python& & & Python文档中心RubyCPU与编译器嵌入式开发驱动开发Web开发VoIP开发技术MySQL& & & MySQL文档中心SybaseOraclePostgreSQLDB2Informix数据仓库与数据挖掘NoSQL技术IT业界新闻与评论IT职业生涯& & & 猎头招聘IT图书与评论& & & CU技术图书大系& & & Linux书友会二手交易下载共享Linux文档专区IT培训与认证& & & 培训交流& & & 认证培训清茶斋投资理财运动地带快乐数码摄影& & & 摄影器材& & & 摄影比赛专区IT爱车族旅游天下站务交流版主会议室博客SNS站务交流区CU活动专区& & & Power活动专区& & & 拍卖交流区频道交流区
富足长乐, 积分 5440, 距离下一级还需 2560 积分
论坛徽章:0
python在windows下有什么模块可以控制鼠标和键盘吗?
想写个程序自动控制鼠标和键盘完成任务
&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp
富足长乐, 积分 5440, 距离下一级还需 2560 积分
论坛徽章:0
&&& from ctypes import *
&&& windll.user32.SetCursorPos(100, 100)
复制代码
论坛徽章:1
楼上搞定了没?
富足长乐, 积分 5440, 距离下一级还需 2560 积分
论坛徽章:0
搞定了几个东西
1,取得鼠标位置,get_mpos()
2,移动鼠标,set_mpos()
3,鼠标左键点击,move_click()
4,键盘输入(部分搞定,那个scancode还不明白是啥意思,为什么0x99输出的是字符'p'???)
from ctypes import *
import time
#&some pos&
win_start = (9, 753)
close_window = (1017, 4)
#&/some pos&
PUL = POINTER(c_ulong)
class KeyBdInput(Structure):
& & & & _fields_ = [(&wVk&, c_ushort),(&wScan&, c_ushort),(&dwFlags&, c_ulong),(&time&, c_ulong),(&dwExtraInfo&, PUL)]
class HardwareInput(Structure):
& & & & _fields_ = [(&uMsg&, c_ulong),(&wParamL&, c_short),(&wParamH&, c_ushort)]
class MouseInput(Structure):
& & & & _fields_ = [(&dx&, c_long),(&dy&, c_long),(&mouseData&, c_ulong),(&dwFlags&, c_ulong),(&time&,c_ulong),(&dwExtraInfo&, PUL)]
class Input_I(Union):
& & & & _fields_ = [(&ki&, KeyBdInput),(&mi&, MouseInput),(&hi&, HardwareInput)]
class Input(Structure):
& & & & _fields_ = [(&type&, c_ulong),(&ii&, Input_I)]
class POINT(Structure):
& & & & _fields_ = [(&x&, c_ulong),(&y&, c_ulong)]
#&Get Pos&
def get_mpos():
& & & & orig = POINT()
& & & & windll.user32.GetCursorPos(byref(orig))
& & & & return int(orig.x), int(orig.y)
#&/Get Pos&
#&Set Pos&
def set_mpos(pos):
& & & & x,y = pos
& & & & windll.user32.SetCursorPos(x, y)
#&/Set Pos&
#&move and click&
def move_click(pos, move_back = False):
& & & & origx, origy = get_mpos()
& & & & set_mpos(pos)
& & & & FInputs = Input * 2
& & & & extra = c_ulong(0)
& & & & ii_ = Input_I()
& & & & ii_.mi = MouseInput( 0, 0, 0, 2, 0, pointer(extra) )
& & & & ii2_ = Input_I()
& & & & ii2_.mi = MouseInput( 0, 0, 0, 4, 0, pointer(extra) )
& & & & x = FInputs( ( 0, ii_ ), ( 0, ii2_ ) )
& & & & windll.user32.SendInput(2, pointer(x), sizeof(x[0]))
& & & & if move_back:
& & & & & & & & set_mpos((origx, origy))
& & & & return origx, origy
#&/move and click&
def sendkey(scancode, pressed):
& & & & FInputs = Input * 1
& & & & extra = c_ulong(0)
& & & & ii_ = Input_I()
& & & & flag = 0x8 # KEY_SCANCODE
& & & & ii_.ki = KeyBdInput( 0, 0, flag, 0, pointer(extra) )
& & & & InputBox = FInputs( ( 1, ii_ ) )
& & & &
& & & & if scancode == None:
& & & & & & & & return
& & & & InputBox[0].ii.ki.wScan = scancode
& & & & InputBox[0].ii.ki.dwFlags = 0x8&&# KEY_SCANCODE&&
& & & & if not(pressed):
& & & & & & & & InputBox[0].ii.ki.dwFlags |= 0x2 # released
& & & & windll.user32.SendInput(1, pointer(InputBox), sizeof(InputBox[0]))
& & & & if pressed:
& & & & & & & & print &%x pressed& % scancode
& & & & else:
& & & & & & & & print &%x released& % scancode
if __name__ == '__main__':
& & & & origx, origy = get_mpos()
& & & & print 'Orig Pos:', origx, origy
& & & & #set_mpos(9, 753)
& & & & #move_click(win_start)
& & & & move_click((800,600))
& & & & time.sleep(1)
& & & & sendkey(0x99,1)
& & & & #keyboard_input()
& & & &
& & & & #set_mpos(origx, origy)
论坛徽章:1
哦,原来是这个思路啊。不知道 Perl Win32::GuiTest 的那种思路在 Python 中有对应的实现吗?借鉴一下。
看看我每天都要用的一个小脚本(自动开启虚拟机):
use Win32::GuiTest qw(:ALL);
our $timeoutFlag = 0;
$SIG{'__DIE__'} = sub{ print &$_[0]按回车键退出&; && };
my $VMPath = shift || die &用法:$0 &VirtualMachine Path& &VM Name&\n&;
my $VMName = shift || die &用法:$0 &VirtualMachine Path& &VM Name&\n&;
my $OpenPietty =
die &文件 $VMPath 不存在。\n& unless -f $VMP
`start $VMPath`;
my $desktop = GetDesktopWindow();
my ($win) = WaitWindowLike( $desktop, &$VMName - VMware Workstation&, '^VMUIFrame$', undef, undef, 10 );
die &没有找到虚拟机窗口。请检查虚拟机名称是否的确是: [$VMName].\n& unless $
SetForegroundWindow($win);
SendKeys( '%mpp' );
ShowWindow( $win, 0 );
exec('pietty') if $OpenP
exit(0);复制代码
用法:
D:\MoChou\perl\StartVMware.pl F:\Debian\Debian.vmx Debian yes复制代码
富足长乐, 积分 5440, 距离下一级还需 2560 积分
论坛徽章:0
貌似很好用的样子...
郁闷python咋就没有
论坛徽章:1
原帖由 bleem1998 于
10:56 发表
貌似很好用的样子...
郁闷python咋就没有
应该也有吧。
这些都是 windows 提供的功能了。
如果没有的话,那你给写一个不就得了。
富足长乐, 积分 5440, 距离下一级还需 2560 积分
论坛徽章:0
键盘的基本搞定了
不过只能输入UNICODE的字符
接下来弄屏幕窗口的
类似WaitWindowLike()和GetDesktopWindow()
干巴爹~~干巴爹~~
富足长乐, 积分 5440, 距离下一级还需 2560 积分
论坛徽章:0
有个东西叫AutoIt
用来自动完成工作很不错
脚本还可以编译成exe
放到任何机器上都可以跑
什么都不依赖
貌似不开源
论坛徽章:1
原帖由 bleem1998 于
13:29 发表
有个东西叫AutoIt
用来自动完成工作很不错
脚本还可以编译成exe
放到任何机器上都可以跑
什么都不依赖
貌似不开源
呵呵,其实要找开源的还不如用 Perl。
也可以编译。如何用键盘控制鼠标的移动和击键_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
如何用键盘控制鼠标的移动和击键
&&用键盘操作电脑
阅读已结束,下载文档到电脑
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,方便使用
还剩4页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢java GUI(鼠标键盘事件) - qq_的博客 - CSDN博客
java GUI(鼠标键盘事件)
import java.awt.*;
import java.awt.event.*;
public class MouseAndEvent {
private TextF
MouseAndEvent()
//对图形化界面进行初始化。
public void init()
f=new Frame(&my frame&);
//对frame进行基本设置,该方法包含setsize和setlocation.
f.setBounds(200,200,400,300);
f.setLayout(new FlowLayout());
//定义文本框对象,指定列数。
tf=new TextField(10);
but=new Button(&my button&);
//在显示窗体之前,添加一个文本框。
f.add(tf);
//将组建添加到frame中
f.add(but);
//显示窗体之前,加载一下窗体上的事件。
myEvent();
//显示窗体
f.setVisible(true);
private void myEvent()
//为窗体添加监听器
f.addWindowListener(new WindowAdapter() {
public void windowClosing (WindowEvent e)
System.exit(0);
//为按钮添加活动事件。
but.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println(&action activity&);
//为按钮添加鼠标事件。
but.addMouseListener(new MouseAdapter() {
//鼠标进入按钮事件
int count=0;
int clikcount=0;
public void mouseEntered(MouseEvent e)
System.out.println(&鼠标进入该组件&+count++);
public void mouseClicked(MouseEvent e)
//获取鼠标点击次数,实现双击
if(e.getClickCount()==2)
System.out.println(&双击组件&+clikcount++);
//为but添加键盘事件。
but.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
//KeyCode()打印键名,KeyChar()打印键所对应的码。
//getKsyText根据键码获取键文本(String)。
//KeyEvent是类名。VK_ESCAPE是按键所对应的静态常量。
if(e.isControlDown()&&e.getKeyCode()==KeyEvent.VK_ENTER)
//System.exit(0);
System.out.println(&组合键运行&);
//System.out.println(KeyEvent.getKeyText(e.getKeyCode())+&---&+e.getKeyCode());
//给文本框添加键盘事件
tf.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e)
int code=e.getKeyCode();
//如果文本框输入的不是0到9则显示为不合法数据,而且不会出现在文本 框中。
if(!(code&=KeyEvent.VK_0&&code&=KeyEvent.VK_9))
System.out.println(code+&---不合法数据&);
e.consume();
public static void main(String[] args) {
new MouseAndEvent();
我的热门文章

我要回帖

更多关于 电脑开机键盘鼠标不亮 的文章

 

随机推荐