I have been using a virtual keyboard that uses ctypes in Python 3.3 for a while, and I can't get it to do Ctrl-Shift-Home, among other triple-key expressions, like Ctrl-Alt-Delete. The expression Ctrl-Shift-Home selects the text starting at the cursor going back to the beginning of the text---which works when I press the expression manually, but I cannot get my code to do it.
My code is essentially the same as the code from this stackoverflow answer, and then to do the expression I could do something like
def Ctrl_Shift_Home():
PressKey(0x11) # Ctrl
PressKey(0x10) # Shift
PressKey(0x24) # Home
time.sleep(0.1)
ReleaseKey(0x24)
ReleaseKey(0x10)
ReleaseKey(0x11)
But the above does not select any text. Is this an issue with the code itself, or an issue with triple-key expressions, or is selecting text just not allowed using keyboard events?
Any answers or alternatives would be appreciated! Thank you!
Related
i want to click an element with a value, which will be inserted by user. I tried this:
def transition(action, value=none):
if (action=='next_page'):
button = driver.find_element_by_link_text('"value"')
button.click()
transition('next_page', value='car1')
The problem is that 'car1' value isn't inserted. What can i fix it?
What your code does, is actually calling the find_element function with the string "value", as you wrote it in quotation marks, making it a string literal
button = driver.find_element_by_link_text('"value"')
What you want to do is insert the name of the variable value without any "double" or 'single' quotation marks, like so.
button = driver.find_element_by_link_text(value)
As you are having a hard time dealing with such simple python syntax, I recommend you first learn the bare basics of the language before trying to write applications with it. There are a lot of free resources out there.
I can recommend W3Schools as a website with text and interactive examples or if you are more of the video type of learner, I can recommend the course by freeCodeCamp.org or a video series by Tech With Tim. Though the last one didn't age really well.
So I do: if keyboard.is_pressed("shift + +"):
And it gives me an error.
I need it to be in the same 'command'.
Please don't post this as an answer:
if keyboard.is_pressed("shift") and keyboard.is_pressed("+"):
Thanks in advance!
The reason it doesn't work is due to how keyboard parses this "hotkey" string. This is from the source code:
for step in _re.split(r',\s?', hotkey):
keys = _re.split(r'\s?\+\s?', step)
It just splits on "+" so you end up with ["shift", "", ""], which has two empty strings, hence an error.
You can do it like this:
if keyboard.is_pressed([sc1, sc2]):
where sc1 and sc2 are the "scan codes" of the keys you want.
For example, it might look like this:
if keyboard.is_pressed([56, 89]):
To find the scan codes, use a script like this:
import keyboard
while True:
print(keyboard.read_event().scan_code)
Just run that script and press the keys you are interested in to see their scan codes get printed. Use these for sc1 and sc2 in the first code block in this answer.
From reading the source code, this should also work:
if keyboard.is_pressed(["shift", "+"]):
but it doesn't work for me. Maybe it will work for you.
Warning: This keyboard module will sometimes have different scan_codes for different keyboards and different operating systems.
I am using Sikuli to create an automation script and am currently struggling with the 'type' function as the input I am attempting to type has quote marks.
Example:
type('h', Key.CTRL)
wait(1)
type('<tbody class="MenuTableBody">')
The actual outcome when it types this is:
<tbody class=#MenuTableBody#>
Any help is appreciated.
Cheers,
Jack
Workaround maybe worth trying is first define the string.
stringSample = str('<tbody class="MenuTTableBody">')
type(stringSample)
The following youtube video shows that it is possible to jump to definition using vim for python.
However when I try the same shortcut (Ctrl-G) it doesnt work...
How is it possible to perform the same "jump to definition"?
I installed the plugin Ctrl-P but not rope.
This does not directly answer your question but provides a better alternative. I use JEDI with VIM, as a static code analyser, it offers far better options than ctags. I use the spacemacs key-binding in vim so with localleader set to ','
" jedi
let g:jedi#use_tabs_not_buffers = 0 " use buffers instead of tabs
let g:jedi#show_call_signatures = "1"
let g:jedi#goto_command = "<localleader>gt"
let g:jedi#goto_assignments_command = "<localleader>ga"
let g:jedi#goto_definitions_command = "<localleader>gg"
let g:jedi#documentation_command = "K"
let g:jedi#usages_command = "<localleader>u"
let g:jedi#completions_command = "<C-Space>"
let g:jedi#rename_command = "<leader>r"
Vim's code navigation is based on a universal database called tags file. It needs to be generated (and updated) manually. :help ctags lists some applications that can do that. Exuberant ctags is a common one that supports many programming languages, but there are also specialized ones, like ptags.py (found in your Python source directory at Tools/scripts/ptags.py).
Plugins like easytags.vim provide more convenience by e.g. automatically updating the tags file on each save.
The default command for jumping to the definition is CTRL-] (not CTRL-G; that prints the current filename; see :help CTRL-G), or the Ex command :tag {identifier}; see all at :help tag-commands.
Some suggestions for people reading other answers to this question in the future:
tags file has one limitation. If in your code multiple objects has the same name you will have problem using ctrl-] as it will jump to first one and not necessary correct one. In this situation you can use g ctrl-] (or :tjump command or :tselect command) to get selection list. Potentially you want to map ctrl-] to "g ctrl-]"
It is possible that you want to have possibility to jump to correct object. In that case you might want to use jedi vim and if you are used to c-] you might want to use this mapping for jedi goto let g:jedi#goto_command = ""
Lastly you want to use universal ctags instead of excuberant ctags because of better new files support (not necessary python).
If you're using YouCompleteMe there is a command for that
:YcmCompleter GoToDefinition
if you want to add a shortcut for doing that in a new tab
nnoremap <leader>d :tab split \| YcmCompleter GoToDefinition<CR>
Motivation: I was going around assigning parameters read in from a config file to variables in a function like so:
john = my_quest
terry = my_fav_color
eric = airspeed
ni = swallow_type
...
when I realized this was going to be a lot of parameters to pass. I thus decided I'd put these parameters in a nice dictionary, grail, e.g. grail['my_quest'] so that the only thing I needed to pass to the function was grail.
Question: Is there a simple way in Sublime (or Notepad++, Spyder, Pycharm, etc.) to paste grails['variable'] around those variables in one step, instead of needing to paste the front and back seperately? (I know about multiple cursors in Sublime, that does help, but I'd love to find a "highlight-variable-and-hit-ctrl-meta-shift-\" and it's done.)
Based on examples you provided, this is a simple task solvable using standard regex find/replace.
So in Notepad++, record this macro (for recording control examine Macro menu):
Press Ctrl+H to open Find/Replace dialog
Find what: = (.*)$
Replace with: = grail['\1']
Choose Regular Expression and press Replace All
If you finish recording the macro and you choose to save it, shortcut key is requested. Assign your favorite ctrl-meta-shift-\ and you are done.