Cursor in python - operating-system

I am trying to make a computer-like cursor which moves when you press the arrow keys on the keyboard, I am using the keyboard extension. Here's the code:
import os
import keyboard
cursor = "🡼"
count = 0
cursorPOS=""
cursorPOSl=""
cursorPOSr=""
while True:
count = count + 1
os.system('cls')
print(cursorPOS,cursor)
cursorPOS= cursorPOSl + "" + cursorPOSr
import keyboard
while True:
try:
if keyboard.is_pressed('right'):
print('')
break # finishing the loop
except:
break
I am stuck at the if keyboard is pressed part, there any way to detect and make the cursor move? Also, I didn't make the code for the cursor showing, but that's a second problem
Any tips on how to do those things?
Didn't exactly try something, just trying to discover what to do

Related

Is there a way to move the cursor of TextField to the end of the text when editing?- SwiftUI

I have created a textfield in Swift UI and I'm looking for a way to make the cursor of the textfield on editing to be at the end of the text even if I tapped the first letter on the textfield.
I think you mean something like this, to set .endOfDocument:
let endPosition = textField.endOfDocument
textField.selectedTextRange = textField.textRange(from: endPosition, to: endPosition)
Now it will stay at the end of the position. If you search something more advanced, I recommend you this post and its answer.

Need to send mouse wheel up when SHIFT key is down and left mouse is clicked?

I want to remap left click of my mouse to mouse wheel up when a certain keyboard key(let's say SHIFT) is hold. It should go back to normal after the key is released.
Here is my current script:
Loop
{
If(GetKeyState("Shift", "P"))
LButton::WheelUp
If(GetKeyState("Shift", "P")=0)
Hotkey, *LButton, off
}
I have two problems with it:
It remaps my left button without any pressed key.
I want it to continuously do "wheel up" as long as the SHIFT key is down and the left mouse button is pressed.
The following will send WheelUp every 0.5 seconds as long as SHIFT and left mouse button are pressed:
+LButton::
sendWheelUp := true
while (sendWheelUp) {
send, {WheelUp}
sleep 500
}
return
+LButton up::sendWheelUp := false
You can adjust sleep time to increase or decrease the frequency.

Removing x number of characters from the caret position in tinyMCE

I am working on a project where the user can enter a special character and then tab to auto complete the values. This part is mostly working, but I want to be able to delete x number of characters from before the caret position.
E.g. if | is the caret and I have the following text #chr|.
I want to be able to delete 3 characters before the cursor position, e.g. I would just end up with #.
I have found a way to get the current cursor position using the below code, but I haven't been able to find any way of being able to delete x number of characters from that position.
function getCaretPosition()
{
var ed = tinyMCE.get('txtComment'); // get editor instance
var range = ed.selection.getRng().startOffset; // get range
return range;
}
You can do this by creating a Range ending at the current caret position:
var ed = tinyMCE.get("mce_0"); // get editor instance
var editorRange = ed.selection.getRng(); // get range object for the current caret position
var node = editorRange.commonAncestorContainer; // relative node to the selection
range = document.createRange(); // create a new range object for the deletion
range.selectNodeContents(node);
range.setStart(node, editorRange.endOffset - 3); // current caret pos - 3
range.setEnd(node, editorRange.endOffset); // current caret pos
range.deleteContents();
ed.focus(); // brings focus back to the editor
To use the demo, position the caret somewhere in the text and then click the "Remove 3" button at the top to delete the preceding 3 characters.
Note that my demo is simplified and doesn't do any bounds checking.
Demo: http://codepen.io/anon/pen/dWVWYM?editors=0010
Compatibility is IE9+

Autohotkey loop sequence with idle reset

I cobbled the following together from various posts:
keys = 0,9,8,7
loop, parse, keys, `,
{
Key_%A_Index% := A_LoopField
KeyCount++
}
return
XButton1::
Rotation ++
Send % Key_%Rotation%
if Rotation = %KeyCount%
Rotation = 0
return
#Persistent
SetTimer, Check, 1000 ;check every second
return
Check:
If (A_TimeIdle >= 3000)
Rotation = 0
return
The idea being that I press my mouse4 button and it cycles through the keys and then goes back to start, however I also wanted a loop so that if I don't press the button for 3 seconds, it resets back to the start of the sequence. The key sequence works however the idle reset doesnt and I'm not sure where to go from here to debug it.
1- You must let the #Persistent SetTimer, Check, 1000 part before the first return.
2- A_TimeIdle is sensible to any input, even a simple mouse move (by user or by script) resets it to zero. If you want to get the Idle time of this single hotkey use A_TimeSinceThisHotkey instead:
Check:
if (A_TimeSinceThisHotkey >= 3000)
{
Rotation = 0
}
return

Setting up some properties for a combobox (scroll, edit, jump)

There are 3 properties that I want to set for some VBA form comboboxes and I don't know if it's possible.
I don't want to let the combobox editable. Right now if the user types something in it that it submits the form it will send that value... I want to let him choose only from the values I added in the Combobox.
I want to make the list of items in the combobox scroll-able. Right now I'm able to scroll through the list if I use the scroll-bar but I don't know why I can't scroll with the mouse scroll.
And I want to jump to some item if I start typing. Let's say I have the months of the year in one combobox... if I start to type mar I want it to jump to march. I know that for the html forms this properties is by default but I don't know about VBA forms...
Thanks a lot
Of the behaviours you want, some are possible with settings on the Combo, others you will need to code
List of Months: Put a list of entries on a (hidden) sheet and name the range. Set .RowSource to that range
Match as you type: Set properties .MatchEntry = fmMatchEntryComplete and .MatchRequired = True
Reject non list entries: A Combo with these settings will allow you to type an invalid entry, but will reject it with an error message popup when you commit. If you want to silently reject invalid data as you type, you will need to code it.
If you want the selected value returned to a sheet, set .ControlSource to a cell address (preferable a named range)
By "...scroll with the mouse scroll..." I assume you mean the mouse wheel. Unfortunatley Forms don't support mouse wheel scroll. You will have to code it yourself. There is a Microsoft patch for this at here (not tried it myself yet)
Sample code to silently reject invalid entries
Private Sub cmbMonth_Change()
Static idx As Long
Dim Match As Boolean
Dim i As Long
If cmbMonth.Value = "" Then Exit Sub
If idx = 0 Then idx = 1
i = idx
Match = False
For i = 0 To cmbMonth.ListCount
If cmbMonth.List((i + idx - 1) Mod cmbMonth.ListCount) Like cmbMonth.Value & "*" Then
cmbMonth.ListIndex = (i + idx - 1) Mod cmbMonth.ListCount
Match = True
Exit For
End If
Next
If Not Match Then
cmbMonth.Value = Left(cmbMonth.Value, Len(cmbMonth.Value) - 1)
End If
End Sub
Set the propertie MatchEntry of combobox to 1 (fmMatchEntryComplete) and MatchRequired to true for example
combobox1.MatchEntry=1
combobox1.MatchRequired=True
[]'s