Of late, Windows has decided to open every PowerShell console such that the prompt is invisible and off the screen below the taskbar. This is quite annoying. I would like something that I can put into my $profile that will either position every new console centrally in the screen, or snap it to the left (or right) of the screen, or maximise it, or (would require a bit more logic I guess) "if part of console is invisible move it up until it is visible".
I know we can get the monitor size as follows, but can anyone show me a good way to use these (or some other method) to reposition any PowerShell console window that I open is not subject to this problem on opening?
$monitor = Get-Wmiobject Win32_Videocontroller
$monitor.CurrentHorizontalResolution => 1920
$monitor.CurrentVerticalResolution => 1080
I've also seen things like this. Can this be exploited to get the PowerShell console that was just opened and move it?
$IE = New-Object -ComObject Internetexplorer.application
$IE.Left = 0
$IE.Width = 500
$IE.Top = 0
$IE.Height = 500
$IE.Navigate($URL)
$IE.Visible = $True
Or something like this
(Get-Process).MainWindowTitle -like '*PowerShell*'
But this is not ideal as it relies on "PowerShell" in the title which might not be the case if I change the title (I like to put the uptime in the Title).
I'd also love a way to open 2 PowerShell consoles and then snap them left and right, or 4 PowerShell consoles and snap them to four corners (maybe someone has built tricks like this already that would be nice to have)?
Have found that AutoHotKey is very good for window positioning tasks.
Here is an example script. Call it psrun.ahk and then run it from the Powershell or double click on it.
Run, Powershell.exe
WinWait, ahk_class WindowTitle
WinActivate
WinMove A, X, Y, X, Y
It will start an powershell window and you can adjust window movement by changing X and Y params and WindowTitle
Found some answers, so I'll just put them here in case of use to others. I've not found a way to position two console windows to each side, or four consoles to each corner yet, so if anyone has that, would appreciate.
First, I found both of these in another StackOverflow answer https://gallery.technet.microsoft.com/scriptcenter/Set-the-PowerShell-Console-bd8b2ad1
, and part of that is nice and concise in that it can move and resize a window. Note in particular the use of -6 for the X position. This is not in the answer, but I know that this corresponds to snapping a window to the edge of the screen so that it's tight to the edge so I now use that (someone on that thread suggests -7 but that's not correct as you can clearly see if you snap to edge after going to -7, that the window pulls out from the edge, so -6 is the correct position):
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int W, int H); '
$consoleHWND = [Console.Window]::GetConsoleWindow();
$consoleHWND = [Console.Window]::MoveWindow($consoleHWND, -6, 0, 600, 650);
That's great, and I could probably do everything with the above, but I have to also calculate screen width etc, but this function nicely does that to fit everything to the screen (it cannot move the window but it can alter the size nicely to match the size of the screen), so in the end I've settled on running the above first in my $profile, followed by the below function.
function Global:Set-MaxWindowSize {
if ($Host.Name -match "console")
{
$MaxHeight = $host.UI.RawUI.MaxPhysicalWindowSize.Height
$MaxWidth = $host.UI.RawUI.MaxPhysicalWindowSize.Width
$MyBuffer = $Host.UI.RawUI.BufferSize
$MyWindow = $Host.UI.RawUI.WindowSize
$MyWindow.Height = ($MaxHeight)
$MyWindow.Width = ($Maxwidth-2)
$MyBuffer.Height = (9999)
$MyBuffer.Width = ($Maxwidth-2)
$host.UI.RawUI.set_bufferSize($MyBuffer)
$host.UI.RawUI.set_windowSize($MyWindow)
}
}
Related
I want to make a gui that show your coordinates in game with text labels but my script seems didn't change the text at all
players = game.Players.LocalPlayer
players.CharacterAdded:Wait()
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
text = script.Parent.Text
while true do
text = X..","..Y..","..Z
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
end
please help me
I wanted to change the text to XYZ position in string
but everytime i launch the game the text didnt change
and it still at default text in roblox ui text label
The simple answer to your question of how do I change a TextLabel text is you just set the Text property.
script.Parent.Text = "Hello World"
If you want a simple way to track the changing position of a player's character, I would recommend using the Changed signal on the Part. It will fire the connected function every time the property changes, and it allows you to avoid using an infinite while-loop.
local text = script.Parent
local player = game.Players.LocalPlayer
-- wait for the player's character to exist
if not player.Character then
player.CharacterAdded:Wait()
end
-- listen for changes to the player's position
local hrp = player.Character.HumanoidRootPart
hrp:GetPropertyChangedSignal("Position"):Connect(function()
local position = hrp.Position
local x, y, z = math.floor(position.X), math.floor(position.Y), math.floor(position.Z)
-- format the position, and display it in the TextLabel
local positionString = string.format("(%d, %d, %d)", x, y, z)
text.Text = positionString
end)
So I can see that you have made few mistakes here
Explanation:
First of all, players.CharacterAdded:Wait() doesn't always work and never works in studio. So instead of that, you should use players.Character:WaitForChild("HumanoidRootPart").
Second thing. By calling text = script.Parent.Text you were requesting the text inside of it (you were getting it as a string), so to simply fix that you have to use text = script.Parent and then when changing text you will have to use text.Text = "your text".
The next one is making your while loop infinite by using bool true. You can't make it like that or else the playar may experience lag or even script may crash. So I'd suggest to put this to something like wait(0.1).
And the last thing is that you should get X,Y,Z before putting it into the text or else it will be delayed.
And your final script should be looking like this:
players = game.Players.LocalPlayer
players.Character:WaitForChild("HumanoidRootPart")
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
text = script.Parent
while wait(0.1) do
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
text.Text = X..","..Y..","..Z
end
Keep scripting, nothing is easy without practice,
KubaDC
I am new to GlovePie.
I created a second mouse that moves simultaneously with the first pointer while staying at a fixed distance. My intent is to get a left click from both pointers simultaneously, because my aim is to click on two buttons simultaneously.
Is it possible to do this?
The code I wrote, following the developer's wiki, is this:
Cursor2.PosX = Mouse.CursorPosX + 80
Cursor2.PosY = Mouse.CursorPosY + 0
Cursor2.LeftButton = Mouse.LeftButton
Cursor2.RightButton = Mouse.RightButton
Very simply. Moving works but simultaneous clicks don't. Any suggestions?
A friend of mine found online the solution to my request, which I share here even if I cannot fully understand its code. For example: why there are two mouse (mouse and mouse1) and two cursor (Cursor and Cursor2)? So if any of you are able to comments the lines of code, I would be grateful to understand them!
mouse.Swallow = true
fakemouse.DirectInputX = mouse1.DirectInputX
fakemouse.DirectInputY = mouse1.DirectInputY
var.x1 = mouse1.cursorPosX
var.x2 = 350
mouse.LeftButton = mouse1.LeftButton
if !mouse1.LeftButton then
Cursor2.PosX = var.x1 - var.x2
Cursor2.PosY = mouse1.cursorPosY
endif
if mouse1.LeftButton then
press mouse1.LeftButton
wait 20ms
release mouse1.LeftButton
Cursor2.PosX = var.x1
Cursor.PosX = var.x1 - var.x2
press mouse1.LeftButton
wait 20ms
release mouse1.LeftButton
Cursor2.PosX = var.x1
Cursor.PosX = var.x1 + var.x2
endif
I'm trying to animate the results of a mathematical process in a 2D canvas with Tk. I've decided to do it with Tk and not SDL because right now i'm working with both Linux and Windows machines and Strawberry Perl doesn't compile proberly in windows, whil Tk is up on both pcs.
What i would like to do with Tk is that:
1)Popping up the canvas while my program is working out the coordinates of the points i would like to draw.
2)Drawing them instantly into the canvas without waiting for the process to reach the end
It's actually a simple animation, where a bunch of points moves around the Canvas while my script updates their coordinates.
Here you have a code snippet i've been writing so far for a single point:
use Tk;
#calcuate the coordinate of a single point
$x=10;
$y=10;
$top = MainWindow->new();
# create a canvas widget
$canvas = $top->Canvas(width => 600, height => 400) -> pack();
# For example, let's create 1 point inside the canvas
$canvas->create ('oval', $x, $y, $x+3, $y+3, -fill=>"black"); # fill color of object
MainLoop;
The problem with the above code is that i would like to add my 'math' script inside it in order to update the $x and $y coordinates above (with some sort of for/while cycle) without shutting down the original canvas, by obtaining a single point moving all around it (atually there are more points i'm supposed to display but that's a minor detail).
FYI, using a simple for cycle embedding the ''Mainloop'' directive doesn't fix the problem.
Thanks in advance guys
Quoting from Mastering Perl/Tk, chapter 15 "Anatomy of the MainLoop":
Option 1: use your own MainLoop implementation
use Tk qw(:eventtypes);
while (Tk::MainWindow->Count) {
# process events - but don't block waiting for them
DoOneEvent(ALL_EVENTS | DONT_WAIT);
# your update implementation goes here
}
Option 2: use a repeat timer event
Later in the chapter it is stated that DoOneEvent() isn't really necessary for most stuff. You could use timer events instead, e.g.
my $update = sub {
# your update implementation goes here
};
# run update every 50ms
$top->repeat(50, $update);
MainLoop;
SOLUTION:
As per Stefan Becker suggested option nr.2, here is what has finally fixed the problem:
use Tk:
$top = MainWindow->new();
# create a canvas widget
$canvas = $top->Canvas(width => 600,
height => 400,
background => 'black') -> pack();
$x=300;
$y=200;
my $update = sub {
$canvas->delete('all'); #unquote this line if you don't want the original point positions to be drawn in the canvas. Viceversa
$x=$x+(-5+rand(10)); #white noise
$y=$y-(-5+rand(10)); #white noise
$canvas->create ('oval', $x , $y , $x+5, $y+5, -fill=>"red");
};
$top->repeat(50, $update);
MainLoop;
I've just added the statement $canvas->delete('all') at the beginning of the updating loop in order to draw just actual points and not the history.
When you touch the screen in Windows 8, the mouse pointer is hidden until you move the mouse (or other pointing device). This happens in both desktop and Metro interfaces.
We have a program that allows people to move the mouse pointer using other input methods (such as a joystick), so I need to ensure the mouse pointer is visible.
How can I force the mouse pointer to be displayed?
you can set the flag of touch feedback.
[setting] ->[control panel]->[pen and touch]->[touch feekback] item,there is a checkbox that is [show visual feedback when touch the screen].If you cann't select the checkbox, you can show the mouse pointer without coding anything when touching the screen.
You can inject mouse movement before you start joystick control, using Windows API:
POINT p;
GetCursorPos(&p);
MOUSEINPUT mi;
mi.dx = (LONG) ((p.x * 65535) / screen_width);
mi.dy = (LONG) ((p.y * 65535) / screen_height);
mi.mouseData = 0;
mi.dwFlags = type | MOUSEEVENTF_ABSOLUTE;
mi.time = 0;
mi.dwExtraInfo = NULL;
INPUT input;
input.type = INPUT_MOUSE;
input.mi = mi;
SendInput(1, &input, sizeof(INPUT));
This works:
(Get-Host).UI.RawUI
$a = (Get-Host).UI.RawUI
$a.BackgroundColor = "white"
$a.ForegroundColor = "black"
$size = (Get-Host).UI.RawUI.WindowSize
$size.Width = 80
$size.Height = 30
(Get-Host).UI.RawUI.WindowSize = $size
But this doesn't work, and I am not sure how to make it work:
$position = (Get-Host).UI.RawUI.Windowposition
$position.X = 0
$position.Y = 30
(Get-Host).UI.RawUI.Windowposition = $position
The error I get is strange. It complains about "buffer" when I am trying to set external window position:
Exception setting "WindowPosition": "Cannot use the
specified Window X (column) position because it extends
past the width of the screen buffer. Specify another X
position, starting with 0 as the left most column of
the buffer.
The error is not really strange, because WindowPosition Gets and sets the position, in characters, of the view window relative to the screen buffer.
It does not set the position of the Window, but to put it crudely, the position in the buffer that you see through the view of the window. So in your case, you are getting the error because it is outside the buffer.
http://msdn.microsoft.com/en-us/library/system.management.automation.host.pshostrawuserinterface.windowposition%28v=vs.85%29.aspx
Unfortunately, setting the position of the window is not simple. There is a snapin for it though - http://wasp.codeplex.com/ ( use Set-WindowPosition)
Take a look at this script: Resize-Console.ps1 – Resize console window/buffer using arrow keys.
It is hopefully useful itself and partially should answer the question (the size part).