Assign shortcut to a "Saved Function"
-
@JamesWebb said in Assign shortcut to a "Saved Function":
My apology Sir!! I didn’t notice your knowledge is beyond my dizzy!!! Because I am not programmer! What a great help! Many thanks you just wasted your time Sir. Please get back to your work Sir.
It is hard to tell if you are being serious or not.
In the event you are serious, there is no apology needed, as this site exists for asking questions, getting answers, and pondering solutions to difficult problems.That all being said, perhaps there IS an acceptable way to implement your desire, again with a scripting plugin. But…you’d have to be willing to hold down Ctrl and Shift together for some predefined period of time. If no additional keypress occurs during that time, the LTR/RTL mode could then be toggled. At least, in theory it could work. Let us know what you think of that.
-
@Alan-Kilborn Many thanks for your time. I am seriously serious now! If you don’t mind and you have time (enough time) for my elementary question (!), check my video (link below) to see that you can change text direction by Ctlr+Shift and change the language with Spacebar+Winkey (or Alt+Shift). I am wondering why you are not aware of that shortcut (absolutely no offence) in NP and Word.
My apology if I bother you (seriously). I know most of the programmers are a bit (!) selfish and they like to just show off their knowledge (!!) on forums!
BTW, my knowledge is a little about boxing (about 18 years in rings! 78 K) and I solve my problem in the real world with real things not in a virtual world.
My apology to you is serious because you took your time to help me. Many thanks again.https://mega.nz/file/Jlp3DRrB#5sDs4dfdegdGyoUb2H_qawN5cuEGABLWWyyScV5NQlU
-
I interpret your response to mean that you were annoyed with my response, if so why exactly?
@Alan-Kilborn
What can I say … of all possible combinations I have used the one, maybe there are more that has problems, oh lord :-D -
@JamesWebb said in Assign shortcut to a "Saved Function":
check my video
Note that many of the regulars here have a strict policy against clicking on random links to such filesharing hosts: anything could be on the other end of that link, including a virus or other malware. Further, for those who are in the forum during they day-job, their I.T. departments likely block such filesharing hosts, so even if they were foolish enough to click on the link on your say-so, they would be blocked.
I am wondering why you are not aware of that shortcut (absolutely no offence) in NP and Word.
Because trying those keystrokes in MS Word and MS Notepad does not change anything for me (and presumably for Alan).
This superuser.com conversation shows that you’re not the only one who has seen
Ctrl+Shift
toggling the direction… but that conversation implies that the direction changes based on which shift key is hit (Ctrl+LeftShift
vsCtrl+RightShift
), not thatCtrl+AnyShift
will toggle the direction.My initial guess is that it requires a Windows setup with multiple keyboards/languages defined (and maybe even one of those languages being a RTL language) for that feature to be available to Notepad. And Notepad++ , being a completely different application not published or coded by Microsoft at all, does not have the insight into the Windows OS internals necessary to intuit that you use that feature in MS apps (whereas MS apps probably have access to better internals and documentation regarding hidden elements of the OS).
You have spent a lot of time apologizing to Alan, but haven’t directly answered his question: are you willing to have a
Ctrl+Shift
toggle for the text direction that would (1) require that you install the PythonScript plugin as well as install a script in that plugin, and (2) require that you hold down theCtrl+Shift
for a “long” period of time (my guess is something on the order of 1-2 seconds). -
@PeterJones
1- About the link, I don’t care if anybody doesn’t like or can’t use them. MEGA is my lovely file-sharing host. If you read my post carefully, you could see I said: “If you don’t MIND!!! (I mean if you LIKE), and have TIME”, you can check the link to see what I am saying about the RTL shortcut in NP and Word. I never FORCE anybody to do something and NEVER had let anybody force me to do something (and I would NEVER let in the future)2- As you are a genius, yes (!), your guess is right! When Alen said he was not aware of that shortcut, my first guess was he had installed just one language (English). The toggle key would be activated if you install another (extra) language on Windows (specifically RTL languages).
3- I think you get me as a foolish-apology-man!!! No bro!!! That apology is because I grew up in a family and I have parents which I kiss their hands day to day. In my region, PERSIA (you call it IRAN!) it’s a normal behaviour here and shows your politeness, not rudeness or foolishness or cowardness!!! They taught me to be polite against anybody older than me. I have to respect his/her age’s number. Using that word is not a symbol of wasting the time to apologise!!! I never owed anybody and would never be! I won’t be annoyed, because I don’t hold annoyance in my brain!!! I’d take care of it (annoyance) by my right (punch) in a millisecond. BTW my right has been crushed, but in the 40s has enough power to respond in millisecond instead of its nanosecond record. If respect bothers you I don’t care. If it annoys you I don’t care at all.
4- Fortunately OR unfortunately English is not my language (native language). If you consider my sentences as wasting the time, it is probably I can’t say that perfectly (fluently) like your natives! I am not a genius like you (!) but as I realized such rubbish things (racism, nationalism, proud of OUR languages!!!, proud of OUR nationality) had disaster consequences like WW#1,#2 and these days it goes to start #3! Humanity always did choose division instead of unification and would choose in the future too! I always have been a hater of these rubbish “-isms”!
My question just started with a simple query! I am an NP++ (portable minimal version) old user. I use that as a simple text editor and a bit more to organizing some files in other formats (that NP++ supports them). If you check them again (all replies), as you are a genius, and your IQ is beyond Einstein’s IQ, instead of punching in a millisecond you would realize every genius instead of replying the answer just explained an Axiom of Choice for me! Maybe I am dumb a bit (!!!), but I am not a donkey! I know if I knew anything about coding, instead of asking about my problem, I would go to download the repo (!!!) to re-compile (if I am saying it correctly!) the app! No need to waste my time to apology you!!!
I hate, absolutely hate cowards people. No offence, don’t take it seriously. Cowards, always know who I am talking about!
Take care. Have a good job day. You just wasted your time for nothing. Your job-time is important to make the world better place for life!!! AoOoO DEAR…
-
Wow. Calm down. We are all trying to help you.
You still haven’t answered Alan’s question, or my rephrasing of it. If you want help, answer the question. If you don’t want help, you don’t have to respond.
-
…haven’t directly answered his question: are you willing to have a Ctrl+Shift toggle for the text direction that would (1) require that you install the PythonScript plugin as well as install a script in that plugin, and (2) require that you hold down the Ctrl+Shift for a “long” period of time (my guess is something on the order of 1-2 seconds).
I think I see a way for requirement (2) to go away, and just a short blip of Ctrl+Shift (down and then up again) to actuate the functionality!
-
@PeterJones said in Assign shortcut to a "Saved Function":
Wow. Calm down.
Don’t tell me “Calm Down”!!!
Chill out boy… in front of your machine!!! You are not here in front of my face to tell me that. -
@Alan-Kilborn
Do you mean by pressing Ctrl+Shift (at the same time) twice? -
@Alan-Kilborn
I forgot to say (!) in MS Word and MS NP by pressing the left Shift+Ctrl the text direction goes left and by pressing the right Shift+Ctrl the text direction goes right. -
Do you mean by pressing Ctrl+Shift (at the same time) twice?
No, I was trying to illustrate that you’d press and release Ctrl+Shift to toggle the direction. It would work on the release, so if you press and held Ctrl+Shift, as long as you didn’t add anything to that – for example the
f
key which would immediately invoke Find in Files – when you release Ctrl+Shift, the desired action would occur.I forgot to say (!) in MS Word and MS NP by pressing the left Shift+Ctrl the text direction goes left and by pressing the right Shift+Ctrl the text direction goes right.
This was brought up by Peter before but you didn’t comment on it; I guess you were consumed with how to reply to Peter’s other statements.
So what do you want…do you want it to work like you say notepad.exe and Word do?:
- LShift+LCtrl = LTR
- RShift+RCtrl = RTL
-
@Alan-Kilborn said in Assign shortcut to a "Saved Function":
Do you mean by pressing Ctrl+Shift (at the same time) twice?
No, I was trying to illustrate that you’d press and release Ctrl+Shift to toggle the direction. It would work on the release, so if you press and held Ctrl+Shift, as long as you didn’t add anything to that – for example the
f
key which would immediately invoke Find in Files – when you release Ctrl+Shift, the desired action would occur.I forgot to say (!) in MS Word and MS NP by pressing the left Shift+Ctrl the text direction goes left and by pressing the right Shift+Ctrl the text direction goes right.
This was brought up by Peter before but you didn’t comment on it; I guess you were consumed with how to reply to Peter’s other statements.
So what do you want…do you want it to work like you say notepad.exe and Word do?:
- LShift+LCtrl = LTR
- RShift+RCtrl = RTL
How can I enable this behaviour? Changing TD (Text Direction) by pressing/holding Ctrl+Shift, then releasing them. Is it possible without a plugin or scripting? I know nothing about scripting (I know Python is one of the coding languages).
AFAIK minimal portable version has some problems with plugins. I had 2/3 of them installed on plugin folders, and they had a problem. I wrote to their authors, and as I can remember they said it’s something wrong with the minimal portable version, not their plugin. That was years ago, I even can’t remember what the plugin’s name was.By saying that, I mean I forgot to mention this (RCtrl+RShift -> RTL …) in my second post (that I attached a video for You).
Both of your suggestion is OK! Which one is more simple to imply in NP++? How can I enable them?
-
So I started on a solution for this, but it was developed with the original “spec” in force, and that is that Ctrl+Shift would toggle the current text direction.
I will change the solution so that the left set of keys will set LTR and the right set of keys will set RTL, but it will take me a bit to finish it. Check back later.
BTW, I sort of regret taking this on, given what has transpired in this thread, but I will push on because I think the solution is somewhat interesting, and could be of interest to others.
-
@Alan-Kilborn
What do you mean exactly? Say it directly. Do you mean you regret taking this on because of my replies? Or something else?Despite someone’s words about me in this thread -> …trying to help you!!! I never need any help, never! Need or Help have no room/place in my brain’s dictionary. They are unidentified and unknown to me! I am not familiar with them. If you regret because of MY words! Don’t take it hard, and don’t pressure yourself! Be brave enough to tell it directly! I had no offensive intention to any nationality, person, or language! I just hate coward people which hide behind their machines (PCs, laptops, tablets, smartphones) in their room, and they think they are the brave heart that they are typing a bunch of glyphs on a bunch of pixels! Calm Down! I swear they even know nothing about Calming down! This compound word just had been injected into their brain and blood in their childhood, and they learned just to play it whenever their age number grows! Whenever somebody tells you “Calm Down”, he knows nothing about that he is insisting divert it to you! My response in a millisecond is because I don’t want my “calm down” mode (not mood) to be interrupted even for a millisecond! I am always calm down.
I solve my problems in the real world with real things not with virtual things that I couldn’t touch/smile/see/hear them!This app and all digital things I am using have the role of toys for me, they are not my day-to-day NEEDS. They are just a bunch of 0-1! Nothing more. I wouldn’t die without a bunch of 0-1. Almost all of the day I am walking (not exercising, I don’t do boxing anymore). My job asks me to walk! My job has nothing to do with Windows or Apps! I have no Smart Phone (I hate that), no personal photos/videos/docs on my PC! I am not dependent on digital things. Just FYI. Maybe it helps you to make a better decision! Either don’t do anything or don’t blame anyone. You are doing nothing for ME! There is no “Me” and “I” out there, those are just in YOUR mind and YOUR imagination.
BTW, I assume your finger is not pointing at me (your regret!), and I appreciate your work.
Many thanks for your time and your reply. God bless you and your family! -
Here’s the finished PythonScript2 script. I call the script
ShiftPlusCtrlChangesLtrRtlMode.py
. Further information about obtaining the necessary plugin and setting it up may be found HERE.# -*- coding: utf-8 -*- from __future__ import print_function # references: # https://community.notepad-plus-plus.org/topic/23402/assign-shortcut-to-a-saved-function from Npp import * import ctypes from ctypes import wintypes import platform #------------------------------------------------------------------------------- user32 = ctypes.WinDLL('user32') notepad.hwnd = user32.FindWindowW(u'Notepad++', None) editor1.hwnd = user32.FindWindowExW(notepad.hwnd, None, u'Scintilla', None) editor2.hwnd = user32.FindWindowExW(notepad.hwnd, editor1.hwnd, u'Scintilla', None) LRESULT = wintypes.LPARAM WndProcType = ctypes.WINFUNCTYPE( LRESULT, # return type wintypes.HWND, wintypes.UINT, wintypes.WPARAM, wintypes.LPARAM # arguments ) running_32bit = platform.architecture()[0] == '32bit' SetWindowLong = user32.SetWindowLongW if running_32bit else user32.SetWindowLongPtrW SetWindowLong.restype = WndProcType SetWindowLong.argtypes = [wintypes.HWND, wintypes.INT, WndProcType] GWL_WNDPROC = -4 WM_KEYDOWN = 0x0100 WM_KEYUP = 0x0101 WM_KILLFOCUS = 0x0008 VK_SHIFT = 0x10 VK_LSHIFT = 0xA0 VK_RSHIFT = 0xA1 VK_CONTROL = 0x11 VK_LCONTROL = 0xA2 VK_RCONTROL = 0xA3 #------------------------------------------------------------------------------- class SPCCLRM(object): def __init__(self): self.debug = True if 0 else False self.reset() self.new_editor1_wnd_proc_hook_for_SetWindowLong = WndProcType(self.new_editor1_wnd_proc_hook) self.orig_editor1_wnd_proc = SetWindowLong(editor1.hwnd, GWL_WNDPROC, self.new_editor1_wnd_proc_hook_for_SetWindowLong) self.new_editor2_wnd_proc_hook_for_SetWindowLong = WndProcType(self.new_editor2_wnd_proc_hook) self.orig_editor2_wnd_proc = SetWindowLong(editor2.hwnd, GWL_WNDPROC, self.new_editor2_wnd_proc_hook_for_SetWindowLong) def reset(self): self.waiting_for_lshift_down = self.waiting_for_lctrl_down = self.waiting_for_rshift_down = self.waiting_for_rctrl_down = True self.waiting_for_lshift_up = self.waiting_for_lctrl_up = self.waiting_for_rshift_up = self.waiting_for_rctrl_up = False def key_down(self, key): return (user32.GetAsyncKeyState(key) & 0x8000) != 0 def common_editor_wnd_proc_hook(self, hwnd, msg, wParam, lParam): retval = True editor_num = 1 if hwnd == editor1.hwnd else '2' if msg == WM_KEYDOWN: self.print('editor{e} WM_KEYDOWN wParam={w}/0x{w:X} lParam={l}/0x{l:X}'.format(e=editor_num, w=wParam, l=lParam)) if wParam == VK_SHIFT: if self.key_down(VK_LSHIFT): if self.waiting_for_lshift_down: if not self.waiting_for_lctrl_down: self.waiting_for_lshift_up = self.waiting_for_lctrl_up = True self.waiting_for_lshift_down = False else: # VK_RSHIFT must be down if self.waiting_for_rshift_down: if not self.waiting_for_rctrl_down: self.waiting_for_rshift_up = self.waiting_for_rctrl_up = True self.waiting_for_rshift_down = False elif wParam == VK_CONTROL: if self.key_down(VK_LCONTROL): if self.waiting_for_lctrl_down: if not self.waiting_for_lshift_down: self.waiting_for_lshift_up = self.waiting_for_lctrl_up = True self.waiting_for_lctrl_down = False else: # VK_RCONTROL must be down if self.waiting_for_rctrl_down: if not self.waiting_for_rshift_down: self.waiting_for_rshift_up = self.waiting_for_rctrl_up = True self.waiting_for_rctrl_down = False else: self.reset() #retval = False # set to False if we don't want further processing of this message elif msg == WM_KEYUP: self.print('editor{e} WM_KEYUP wParam={w}/0x{w:X} lParam={l}/0x{l:X}'.format(e=editor_num, w=wParam, l=lParam)) if wParam == VK_SHIFT: if self.waiting_for_lshift_up: if not self.key_down(VK_LSHIFT): if not self.waiting_for_lctrl_up: if self.debug: self.print('LC previously up, now LS up -- set LTR') else: notepad.menuCommand(MENUCOMMAND.EDIT_LTR) self.reset() self.waiting_for_lshift_up = False elif self.waiting_for_rshift_up: if not self.key_down(VK_RSHIFT): if not self.waiting_for_rctrl_up: if self.debug: self.print('RC previously up, now RS up -- set RTL') else: notepad.menuCommand(MENUCOMMAND.EDIT_RTL) self.reset() self.waiting_for_rshift_up = False elif wParam == VK_CONTROL: if self.waiting_for_lctrl_up: if not self.key_down(VK_LCONTROL): if not self.waiting_for_lshift_up: if self.debug: self.print('LS previously up, now LC up -- set LTR') else: notepad.menuCommand(MENUCOMMAND.EDIT_LTR) self.reset() self.waiting_for_lctrl_up = False elif self.waiting_for_rctrl_up: if not self.key_down(VK_RCONTROL): if not self.waiting_for_rshift_up: if self.debug: self.print('RS previously up, now RC up -- set RTL') else: notepad.menuCommand(MENUCOMMAND.EDIT_RTL) self.reset() self.waiting_for_rctrl_up = False else: self.reset() #retval = False # set to False if we don't want further processing of this message elif msg == WM_KILLFOCUS: self.print('editor{e} WM_KILLFOCUS wParam={w}/0x{w:X} lParam={l}/0x{l:X}'.format(e=editor_num, w=wParam, l=lParam)) self.reset() #retval = False # set to False if we don't want further processing of this message return retval def new_editor1_wnd_proc_hook(self, hwnd, msg, wParam, lParam): retval = self.common_editor_wnd_proc_hook(hwnd, msg, wParam, lParam) if retval: retval = self.orig_editor1_wnd_proc(hwnd, msg, wParam, lParam) return retval def new_editor2_wnd_proc_hook(self, hwnd, msg, wParam, lParam): retval = self.common_editor_wnd_proc_hook(hwnd, msg, wParam, lParam) if retval: retval = self.orig_editor2_wnd_proc(hwnd, msg, wParam, lParam) return retval def print(self, *args): if self.debug: #console.show() print('SPCCLRM:', *args) #------------------------------------------------------------------------------- # to run via another file, e.g., startup.py, put these lines (uncommented and unindented) in that file: # import ShiftPlusCtrlChangesLtrRtlMode # spcclrm = ShiftPlusCtrlChangesLtrRtlMode.SPCCLRM() if __name__ == '__main__': SPCCLRM()
-
-