你能给我指一下Powershell鼠标教程吗

你能给我指一下Powershell鼠标教程吗,powershell,Powershell,请有人推荐一个Powershell鼠标教程。我一直在网上搜索,但是找不到关于如何做的说明 我想通过鼠标选择数据库中的数据。我已经能够在文本框中显示数据库的输出,但无法选择它 我希望能够做的是选择输出中的行,然后使用该行中的信息 非常感谢您的任何想法 您可以在Windows上使用Out GridView-PassThru来实现这一点: $selected = $datatable |Out-GridView -PassThru 通过单击(ctrl单击多行)选择相关行,然后单击右下角的Ok $se

请有人推荐一个Powershell鼠标教程。我一直在网上搜索,但是找不到关于如何做的说明

我想通过鼠标选择数据库中的数据。我已经能够在文本框中显示数据库的输出,但无法选择它

我希望能够做的是选择输出中的行,然后使用该行中的信息


非常感谢您的任何想法

您可以在Windows上使用
Out GridView-PassThru
来实现这一点:

$selected = $datatable |Out-GridView -PassThru
通过单击(ctrl单击多行)选择相关行,然后单击右下角的
Ok


$selected
将包含相关行

以下是我自己使用的一些函数。我试着让它们适应你将如何使用它

Add-Type -AssemblyName System.Windows.Forms
$wshell = New-Object -ComObject wscript.shell; 

function Mouse-signature-import(){
    $global:signature=@' 
      [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
      public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
'@ 

    $global:SendMouseClick = Add-Type -memberDefinition $global:signature -name "Win32MouseEventNew" -namespace Win32Functions -passThru 
}


function Mouse-Drag($from1,$from2,$to1,$to2){
    Mouse-signature-import

    [System.Windows.Forms.Cursor]::Position = "$from1,$from2"
    $global:SendMouseClick::mouse_event(0x00000002, 0, 0, 0, 0);
    [System.Windows.Forms.Cursor]::Position = "$to1,$to2"
    start-sleep -m 1500 # If we do not sleep, then the drag does not work right.
    $global:SendMouseClick::mouse_event(0x00000004, 0, 0, 0, 0);

    write-host -f yellow -b black "Mouse-Drag" -nonewline; write-host -f Gray " from " -NoNewline; write-host -f Magenta "[" -nonewline; write-host -f Red "$from1 $from2" -nonewline;write-host -f Magenta "]" -nonewline; write-host -f Gray " to " -NoNewline; write-host -f Magenta "[" -nonewline; write-host -f Red "$to1 $to2" -nonewline; write-host -f Magenta "]";
}

function SendInput($a){

    [System.Windows.Forms.SendKeys]::SendWait($a)

}

start-sleep -s 1 
Mouse-Drag 90 166 126 358
start-sleep -s 1
sendInput "^(c)"

$a = Get-Clipboard
$a
为了计算出鼠标光标要移动到的位置的坐标,我使用以下命令:
https://learn-powershell.net/2015/11/30/create-a-mouse-cursor-tracker-using-powershell-and-wpf/

基本上,我在上面做的是将鼠标移动到光标位置,然后将鼠标拖动到位置2。发送一个CTRL+C复制我们突出显示的内容,然后使用get clipboard将所选文本推送到变量($a)中


这个方法对于您试图做的事情来说并不完美,但这正是您想要做的,所以这就是我提供代码的原因。我建议尝试通过其他方法获取数据,因为这里可能会出现很多错误。

我所做的是从从数据库检索数据的函数(RetriveData)返回一个表

$listTable = RetriveData | Format-Table | Out-String

Write-host “$listTable”

$selected = $listTable | Out-GridView –PassThru

Write-host “$selected”
写主机正在显示我所期望的表内容。Out GridView打开的对话框以浅蓝色突出显示表格,但似乎只能作为完整表格选择。 我在这里是否正确使用了
|格式表|输出字符串

RetriveData函数中用于从数据库返回的代码为

$table = Invoke-Sqlcmd –ServerInstance $databaseServer $databaseName –Query $sql
Return $table

欢迎来到SO!我不建议尝试处理P/调用User32.dll将鼠标移动到特定坐标。你必须考虑很多情况(SSRS应用程序边界、知道滚动窗口在应用程序中的位置等)。如果您只是想从SQL数据库中读取信息,请看Invoke SqlCmdI,我一定是误解了他的要求。@IP3R我也从另一个角度理解了它,直到我找到了“我能够在文本框中显示数据库的输出”部分谢谢您Mathias,这是一种工作方式,但是我不能选择任何东西。谢谢你,马蒂亚斯,这是一种工作,但我不能选择任何东西。该表显示在窗口的字符串部分,但我无法单独选择任何内容。我认为现在的情况是,表格显示为单个项目,您只能选择整个表格。显示$selected会显示整个表。我如何将表格分解成各个部分?@martin你能告诉我们你是如何获得输入的吗?如果可能,请共享您使用的代码