解决方案 »
- 在delphi 中如何将路径写入到写入到系统的path里?
- 急求答案 LoadFromStream(const Stream: IUnknown); 如何调用?
- ms access数据库是否只能有255个字段呢?不能再加了么?
- QQ群:4281029,VB、DELPHI学习群,欢迎加入!!
- midas的简单问题!!!!!!!!!!!!!!!!!!!!
- 怎样将一个文件夹的所有文件读到ComboBox中?
- treeview设计只欠东风了!如何在生成子结点时做个判断?请高手指点!代码如下:
- 如果通过ODBC连接到SQL,那怎么判断是否连接通了?
- 我初学dephi 第五天,高分求解(关于Dephi 的ServerSocket)
- 如何通过HTML控件来调用本机的html文件?
- RichEdit的字体颜色设置。
- 怎樣截取字符串中的指定字符﹖
能不能发一份
[email protected]
能不能发一份
[email protected]
(*//
标题:模拟系统按键
说明:支持组合键;不支持部分系统热键(如:Ctrl+Shift+Del...)
设计:Zswang
日期:2002-01-24
支持:[email protected]
//*)///////Begin Source
procedure SendKey(const mKey: Word; mShiftState: TShiftState;
mCount: Integer = 1); { 模拟系统按键;mCount指定按键次数 }
const
cExtended: set of Byte = [VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_HOME,
VK_END, VK_PRIOR, VK_NEXT, VK_INSERT, VK_DELETE]; procedure pKeyboardEvent(mKey, mScanCode: Byte; mFlags: Longint);
var
vKeyboardMsg: TMsg;
begin
keybd_event(mKey, mScanCode, mFlags, 0);
while PeekMessage(vKeyboardMsg, 0, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) do
begin
TranslateMessage(vKeyboardMsg);
DispatchMessage(vKeyboardMsg);
end;
end; { pKeyboardEvent } procedure pSendKeyDown(mKey: Word; mGenUpMsg: Boolean);
var
vScanCode: Byte;
vNumState: Boolean;
vKeyBoardState: TKeyboardState;
begin
if (mKey = VK_NUMLOCK) then begin
vNumState := ByteBool(GetKeyState(VK_NUMLOCK) and 1);
GetKeyBoardState(vKeyBoardState);
if vNumState then
vKeyBoardState[VK_NUMLOCK] := (vKeyBoardState[VK_NUMLOCK] and not 1)
else vKeyBoardState[VK_NUMLOCK] := (vKeyBoardState[VK_NUMLOCK] or 1);
SetKeyBoardState(vKeyBoardState);
Exit;
end; vScanCode := Lo(MapVirtualKey(mKey, 0));
if (mKey in cExtended) then begin
pKeyboardEvent(mKey, vScanCode, KEYEVENTF_EXTENDEDKEY);
if mGenUpMsg then
pKeyboardEvent(mKey, vScanCode,
KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP)
end else begin
pKeyboardEvent(mKey, vScanCode, 0);
if mGenUpMsg then pKeyboardEvent(mKey, vScanCode, KEYEVENTF_KEYUP);
end;
end; { pSendKeyDown } procedure pSendKeyUp(mKey: Word);
var
vScanCode: Byte;
begin
vScanCode := Lo(MapVirtualKey(mKey, 0));
if mKey in cExtended then
pKeyboardEvent(mKey, vScanCode, KEYEVENTF_EXTENDEDKEY and KEYEVENTF_KEYUP)
else pKeyboardEvent(mKey, vScanCode, KEYEVENTF_KEYUP);
end; { pSendKeyUp }var
I: Integer;
begin
for I := 1 to mCount do begin
if ssShift in mShiftState then pSendKeyDown(VK_SHIFT, False);
if ssCtrl in mShiftState then pSendKeyDown(VK_CONTROL, False);
if ssAlt in mShiftState then pSendKeyDown(VK_MENU, False);
pSendKeyDown(mKey, True);
if ssShift in mShiftState then pSendKeyUp(VK_SHIFT);
if ssCtrl in mShiftState then pSendKeyUp(VK_CONTROL);
if ssAlt in mShiftState then pSendKeyUp(VK_MENU);
end;
end; { SendKey }
///////End Source///////Begin Demo
procedure TForm1.Button1Click(Sender: TObject);
begin
SendKey(VK_F4, [ssAlt]);
end;
///////End Demo
自画,自己标识按钮。
2。如何传递字符串到其它应用程序或其它有焦点窗口?
采用TClipBoard编程或消息通讯或COM接口。
3。如何在按下SHIFT时让它键停在按下状态?
???
给你一个ClipBoard传送数据的例子。unit AutoClipboard;
interface
uses
Clipbrd, //自己添加Clipbrd单元
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
CommCtrl, StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
//接收两个消息
procedure ClipboardChanged(var message: TMessage);message WM_DRAWCLIPBOARD;
procedure ClipboardChangeCBChain(var message: TMessage);message WM_CHANGECBCHAIN;
end;var
Form1: TForm1;
hwndNextViewer:hWnd;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin
//注册成为剪贴板查看器并且保存下一窗口的句柄
hwndNextViewer := SetClipboardViewer(handle);
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//退出程序时调整剪贴板查看链
ChangeClipboardChain(handle, hwndNextViewer);
SendMessage(hwndNextViewer,WM_CHANGECBCHAIN,Handle,hwndNextViewer);
end;procedure TForm1.ClipboardChangeCBChain(var message: TMessage);
begin
//调整剪贴板查看链
with message do
begin
if WParam=hwndNextViewer then
hwndNextViewer := LParam
else if (hwndNextViewer <> 0) then
SendMessage(hwndNextViewer, Msg,wParam, lParam);
end;
end;procedure TForm1.ClipboardChanged(var message: TMessage);
var
s :string;
begin
//以下为剪贴板内容改变时的处理
if Clipboard.HasFormat(CF_TEXT) then //判断剪贴板内容是否为文本
begin
s := Clipboard.astext; //取得剪贴板内文本内容
memo1.lines.add(s);
end;
//向下一链传递消息
if (hwndNextViewer <> 0) then
with message do
SendMessage(hwndNextViewer, Msg,wParam, lParam);
end;end.
2。如何传递字符串到其它应用程序或其它有焦点窗口?
3。如何在按下SHIFT时让它键停在按下状态?
2。如何传递字符串到其它应用程序或其它有焦点窗口?
3。如何在按下SHIFT时让它键停在按下状态?
搞定后能不能发一份到:
[email protected]
在API函数GlobalAddAtom的帮助下可以通过windows信息传送一个字符串。这个函数返回一个数,可以被PostMessage (或SendMessage)中的 wParam 或 lParam 使用。发送方:wParam = GlobalAddAtom('string...')
PostMessage(HWnd, WM_XYZ, wParam, 0)
接收方:str = GlobalGetAtomName(wParam)
GlobalDeleteAtom(wParam)另外判断一下wparam & MK_SHIFT的值如果不为0(true)
则某件按下同时也按下了shift键